@@ -332,9 +332,23 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
332332 pivot_values = [yvar , color_col ]
333333 pivoted_plot_data = pd .pivot (data = plot_data , index = dabest_obj .id_col ,
334334 columns = xvar , values = pivot_values )
335+ if is_paired == "baseline" :
336+ temp_idx = []
337+ for i in idx :
338+ control = i [0 ]
339+ temp_idx .extend (((control , test ) for test in i [1 :]))
340+ temp_idx = tuple (temp_idx )
341+
342+ temp_all_plot_groups = []
343+ for i in temp_idx :
344+ temp_all_plot_groups .extend (list (i ))
345+ else :
346+ temp_idx = idx
347+ temp_all_plot_groups = all_plot_groups
348+
335349 x_start = 0
336- for ii , current_tuple in enumerate (idx ):
337- if len (idx ) > 1 :
350+ for ii , current_tuple in enumerate (temp_idx ):
351+ if len (temp_idx ) > 1 :
338352 # Select only the data for the current tuple.
339353 if color_col is None :
340354 current_pair = pivoted_plot_data .reindex (columns = current_tuple )
@@ -363,8 +377,8 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
363377 rawdata_axes .plot (x_points , y_points , ** slopegraph_kwargs )
364378 x_start = x_start + grp_count
365379 # Set the tick labels, because the slopegraph plotting doesn't.
366- rawdata_axes .set_xticks (np .arange (0 , len (all_plot_groups )))
367- rawdata_axes .set_xticklabels (all_plot_groups )
380+ rawdata_axes .set_xticks (np .arange (0 , len (temp_all_plot_groups )))
381+ rawdata_axes .set_xticklabels (temp_all_plot_groups )
368382
369383
370384 else :
@@ -431,12 +445,19 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
431445
432446 # Plot effect sizes and bootstraps.
433447 # Take note of where the `control` groups are.
434- ticks_to_skip = np .cumsum ([len (t ) for t in idx ])[:- 1 ].tolist ()
435- ticks_to_skip .insert (0 , 0 )
448+ if is_paired == "baseline" and show_pairs == True :
449+ ticks_to_skip = np .arange (0 , len (temp_all_plot_groups ), 2 ).tolist ()
450+ ticks_to_plot = np .arange (1 , len (temp_all_plot_groups ), 2 ).tolist ()
451+ ticks_to_skip_contrast = np .cumsum ([(len (t )- 1 )* 2 for t in idx ])[:- 1 ].tolist ()
452+ ticks_to_skip_contrast .insert (0 , 0 )
453+
454+ else :
455+ ticks_to_skip = np .cumsum ([len (t ) for t in idx ])[:- 1 ].tolist ()
456+ ticks_to_skip .insert (0 , 0 )
436457
437458 # Then obtain the ticks where we have to plot the effect sizes.
438- ticks_to_plot = [t for t in range (0 , len (all_plot_groups ))
439- if t not in ticks_to_skip ]
459+ ticks_to_plot = [t for t in range (0 , len (all_plot_groups ))
460+ if t not in ticks_to_skip ]
440461
441462
442463 # Plot the bootstraps, then the effect sizes and CIs.
@@ -683,22 +704,55 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
683704 if contrast_ylim_low < 0 < contrast_ylim_high :
684705 contrast_axes .axhline (y = 0 , ** reflines_kwargs )
685706
686- # Compute the end of each x-axes line.
687- rightend_ticks = np .array ([len (i )- 1 for i in idx ]) + np .array (ticks_to_skip )
688- for ax in [rawdata_axes , contrast_axes ]:
689- sns .despine (ax = ax , bottom = True )
690-
691- ylim = ax .get_ylim ()
692- xlim = ax .get_xlim ()
693- redraw_axes_kwargs ['y' ] = ylim [0 ]
707+ if is_paired == "baseline" and show_pairs == True :
708+ rightend_ticks_raw = np .array ([len (i )- 1 for i in temp_idx ]) + np .array (ticks_to_skip )
709+ for ax in [rawdata_axes ]:
710+ sns .despine (ax = ax , bottom = True )
694711
695- for k , start_tick in enumerate (ticks_to_skip ):
696- end_tick = rightend_ticks [k ]
697- ax .hlines (xmin = start_tick , xmax = end_tick ,
698- ** redraw_axes_kwargs )
712+ ylim = ax .get_ylim ()
713+ xlim = ax .get_xlim ()
714+ redraw_axes_kwargs ['y' ] = ylim [0 ]
699715
700- ax .set_ylim (ylim )
701- del redraw_axes_kwargs ['y' ]
716+ for k , start_tick in enumerate (ticks_to_skip ):
717+ end_tick = rightend_ticks_raw [k ]
718+ ax .hlines (xmin = start_tick , xmax = end_tick ,
719+ ** redraw_axes_kwargs )
720+
721+ ax .set_ylim (ylim )
722+ del redraw_axes_kwargs ['y' ]
723+
724+ rightend_ticks_contrast = np .array ([(len (i )- 1 )* 2 - 1 for i in idx ]) + np .array (ticks_to_skip_contrast )
725+ for ax in [contrast_axes ]:
726+ sns .despine (ax = ax , bottom = True )
727+
728+ ylim = ax .get_ylim ()
729+ xlim = ax .get_xlim ()
730+ redraw_axes_kwargs ['y' ] = ylim [0 ]
731+
732+ for k , start_tick in enumerate (ticks_to_skip_contrast ):
733+ end_tick = rightend_ticks_contrast [k ]
734+ ax .hlines (xmin = start_tick , xmax = end_tick ,
735+ ** redraw_axes_kwargs )
736+
737+ ax .set_ylim (ylim )
738+ del redraw_axes_kwargs ['y' ]
739+ else :
740+ # Compute the end of each x-axes line.
741+ rightend_ticks = np .array ([len (i )- 1 for i in idx ]) + np .array (ticks_to_skip )
742+ for ax in [rawdata_axes , contrast_axes ]:
743+ sns .despine (ax = ax , bottom = True )
744+
745+ ylim = ax .get_ylim ()
746+ xlim = ax .get_xlim ()
747+ redraw_axes_kwargs ['y' ] = ylim [0 ]
748+
749+ for k , start_tick in enumerate (ticks_to_skip ):
750+ end_tick = rightend_ticks [k ]
751+ ax .hlines (xmin = start_tick , xmax = end_tick ,
752+ ** redraw_axes_kwargs )
753+
754+ ax .set_ylim (ylim )
755+ del redraw_axes_kwargs ['y' ]
702756
703757
704758
0 commit comments