@@ -705,13 +705,20 @@ def select_consecutive_pvalues(
705705
706706 """
707707 pvalues = []
708+
708709 for idx in range (len (conditions_list ) - 1 ):
709710 cond1 = conditions_list [idx ]
710711 cond2 = conditions_list [idx + 1 ]
712+ # get pair
711713 pval = df_pvalues .loc [
712714 (df_pvalues ["A" ] == cond1 ) & (df_pvalues ["B" ] == cond2 ), "p-unc"
713- ].iloc [0 ]
714- pvalues .append (pval )
715+ ]
716+ if len (pval ) == 0 :
717+ # try the reverse pair
718+ pval = df_pvalues .loc [
719+ (df_pvalues ["B" ] == cond1 ) & (df_pvalues ["A" ] == cond2 ), "p-unc"
720+ ]
721+ pvalues .append (pval .iloc [0 ])
715722
716723 return pvalues
717724
@@ -1300,7 +1307,7 @@ def nice_plot_serie(
13001307 )
13011308
13021309 if plot_options ["plot_condition" ]:
1303- # plot mean per animal
1310+ # plot mean per condition
13041311 palette = kwargs_plot ["condition" ]["color" ]
13051312 ax = sns .lineplot (
13061313 df ,
@@ -1363,7 +1370,7 @@ def nice_plot_metrics(
13631370 df : pd .DataFrame ,
13641371 x : str = "condition" ,
13651372 y : str = "" ,
1366- conditions_order : list = [],
1373+ order : list = [],
13671374 pvalues : list | float = 0 ,
13681375 title = "" ,
13691376 ax : plt .Axes | None = None ,
@@ -1381,7 +1388,7 @@ def nice_plot_metrics(
13811388 df : pandas.DataFrame
13821389 x, y : str
13831390 Keys in `df`.
1384- conditions_order : list
1391+ order : list
13851392 Order in which metrics will be plotted.
13861393 pvalues : List
13871394 List of p-values for consecutive conditions to plot stars. If 0, no stars will
@@ -1402,7 +1409,8 @@ def nice_plot_metrics(
14021409 x = x ,
14031410 y = y ,
14041411 hue = x ,
1405- order = conditions_order ,
1412+ order = order ,
1413+ hue_order = order ,
14061414 estimator = "mean" ,
14071415 errorbar = "se" ,
14081416 ax = ax ,
@@ -1419,6 +1427,8 @@ def nice_plot_metrics(
14191427 x = x ,
14201428 y = y ,
14211429 hue = x ,
1430+ order = order ,
1431+ hue_order = order ,
14221432 legend = False ,
14231433 dodge = True ,
14241434 ax = ax ,
@@ -1428,9 +1438,7 @@ def nice_plot_metrics(
14281438 # add significance
14291439 if pvalues :
14301440 # get bar + errorbar value, sorting as sorted in the plot
1431- maxvals = (df .groupby (x )[y ].mean () + df .groupby (x )[y ].sem ())[
1432- conditions_order
1433- ].values
1441+ maxvals = (df .groupby (x )[y ].mean () + df .groupby (x )[y ].sem ())[order ].values
14341442
14351443 for c , pvalue in enumerate (pvalues ):
14361444 ax = add_stars_to_bars (
@@ -1465,6 +1473,7 @@ def nice_plot_bars(
14651473 x : str = "" ,
14661474 y : str = "" ,
14671475 hue : str = "" ,
1476+ hue_order : list = [],
14681477 pvalues : dict | None = None ,
14691478 xlabels : dict = {},
14701479 ylabel : str = "" ,
@@ -1479,6 +1488,8 @@ def nice_plot_bars(
14791488 df : pandas.DataFrame
14801489 x, y, hue : str
14811490 Keys in `df`.
1491+ hue_order : list
1492+ Order in which to plot the hues.
14821493 pvalues : dict
14831494 Mapping a `x` to a list of pvalues for consecutive `hue`.
14841495 xlabels : dict
@@ -1500,6 +1511,7 @@ def nice_plot_bars(
15001511 x = x ,
15011512 y = y ,
15021513 hue = hue ,
1514+ hue_order = hue_order ,
15031515 estimator = "mean" ,
15041516 errorbar = "se" ,
15051517 ax = ax ,
@@ -1515,6 +1527,7 @@ def nice_plot_bars(
15151527 x = x ,
15161528 y = y ,
15171529 hue = hue ,
1530+ hue_order = hue_order ,
15181531 legend = False ,
15191532 dodge = True ,
15201533 ax = ax ,
@@ -1539,9 +1552,9 @@ def nice_plot_bars(
15391552 continue
15401553
15411554 # get bar + errorbar value, sorting as sorted in the plot
1542- maxvals = (
1543- dfpval . groupby ( hue )[ y ]. mean () + dfpval . groupby ( hue )[ y ]. sem ()
1544- ) .values
1555+ maxvals = (dfpval . groupby ( hue )[ y ]. mean () + dfpval . groupby ( hue )[ y ]. sem ())[
1556+ hue_order
1557+ ] .values
15451558
15461559 for c , pval in enumerate (pvalue ):
15471560 xline_0 = xline_center + offsets [c ]
@@ -1888,7 +1901,7 @@ def plot_all_figures(
18881901 df_metrics ,
18891902 x = "condition" ,
18901903 y = metric_name ,
1891- conditions_order = conditions_list ,
1904+ order = conditions_list ,
18921905 pvalues = pvals ,
18931906 title = metric ,
18941907 ax = ax ,
@@ -1927,6 +1940,7 @@ def plot_all_figures(
19271940 x = "feature" ,
19281941 y = "delay" ,
19291942 hue = "condition" ,
1943+ hue_order = conditions_list ,
19301944 pvalues = pval_delays_plt ,
19311945 xlabels = cfg .features_labels ,
19321946 ylabel = "delay (ms)" ,
@@ -1948,6 +1962,7 @@ def plot_all_figures(
19481962 x = "feature" ,
19491963 y = "response" ,
19501964 hue = "condition" ,
1965+ hue_order = conditions_list ,
19511966 pvalues = pval_response_plt ,
19521967 xlabels = cfg .features_labels ,
19531968 ylabel = "response rate" ,
@@ -1964,6 +1979,7 @@ def plot_all_figures(
19641979 x = "feature" ,
19651980 y = "responsiveness" ,
19661981 hue = "condition" ,
1982+ hue_order = conditions_list ,
19671983 xlabels = cfg .features_labels ,
19681984 ylabel = "responsiveness (ms$^{-1}$)" ,
19691985 ax = axrs ,
0 commit comments