@@ -70,6 +70,7 @@ def effectsize_df_plotter(effectsize_df, **plot_kwargs):
7070 show_legend ,
7171 Gardner_Altman_Plot_Aesthetic_Adjustments ,
7272 Cumming_Plot_Aesthetic_Adjustments ,
73+ General_Plot_Aesthetic_Adjustments ,
7374 )
7475 from .plot_tools import (
7576 get_swarm_spans ,
@@ -138,7 +139,8 @@ def effectsize_df_plotter(effectsize_df, **plot_kwargs):
138139 plot_palette_bar , plot_palette_contrast , plot_palette_sankey ) = get_color_palette (plot_kwargs = plot_kwargs ,
139140 plot_data = plot_data ,
140141 xvar = xvar ,
141- show_pairs = show_pairs )
142+ show_pairs = show_pairs
143+ )
142144
143145 # Initialise the figure.
144146 fig , rawdata_axes , contrast_axes , swarm_ylim = initialize_fig (plot_kwargs = plot_kwargs ,
@@ -300,13 +302,6 @@ def effectsize_df_plotter(effectsize_df, **plot_kwargs):
300302 plot_kwargs = plot_kwargs
301303 )
302304
303- # Save the handles and labels for the legend.
304- handles , labels = rawdata_axes .get_legend_handles_labels ()
305- legend_labels = [l for l in labels ]
306- legend_handles = [h for h in handles ]
307- if bootstraps_color_by_group is False :
308- rawdata_axes .legend ().set_visible (False )
309-
310305 # Enforce the xtick of rawdata_axes to be 0 and 1 after drawing only one sankey ----> Redundant code
311306 if one_sankey :
312307 rawdata_axes .set_xticks ([0 , 1 ])
@@ -373,6 +368,12 @@ def effectsize_df_plotter(effectsize_df, **plot_kwargs):
373368 plot_kwargs = plot_kwargs ,
374369 )
375370 # Legend
371+ handles , labels = rawdata_axes .get_legend_handles_labels ()
372+ legend_labels = [l for l in labels ]
373+ legend_handles = [h for h in handles ]
374+ if bootstraps_color_by_group is False :
375+ rawdata_axes .legend ().set_visible (False )
376+
376377 if bootstraps_color_by_group is False :
377378 show_legend (legend_labels = legend_labels ,
378379 legend_handles = legend_handles ,
@@ -383,29 +384,30 @@ def effectsize_df_plotter(effectsize_df, **plot_kwargs):
383384 legend_kwargs = legend_kwargs
384385 )
385386
387+ # Plot aesthetic adjustments.
386388 og_ylim_raw = rawdata_axes .get_ylim ()
387389 og_xlim_raw = rawdata_axes .get_xlim ()
388390
389391 if float_contrast :
390392 # For Gardner-Altman plots only.
391393 Gardner_Altman_Plot_Aesthetic_Adjustments (effect_size_type = effect_size_type ,
392- plot_data = plot_data ,
393- xvar = xvar ,
394- yvar = yvar ,
395- current_control = current_control ,
396- current_group = current_group ,
397- rawdata_axes = rawdata_axes ,
398- contrast_axes = contrast_axes ,
399- results = results ,
400- current_effsize = current_effsize ,
401- is_paired = is_paired ,
402- one_sankey = one_sankey ,
403- reflines_kwargs = reflines_kwargs ,
404- redraw_axes_kwargs = redraw_axes_kwargs ,
405- swarm_ylim = swarm_ylim ,
406- og_xlim_raw = og_xlim_raw ,
407- og_ylim_raw = og_ylim_raw
408- )
394+ plot_data = plot_data ,
395+ xvar = xvar ,
396+ yvar = yvar ,
397+ current_control = current_control ,
398+ current_group = current_group ,
399+ rawdata_axes = rawdata_axes ,
400+ contrast_axes = contrast_axes ,
401+ results = results ,
402+ current_effsize = current_effsize ,
403+ is_paired = is_paired ,
404+ one_sankey = one_sankey ,
405+ reflines_kwargs = reflines_kwargs ,
406+ redraw_axes_kwargs = redraw_axes_kwargs ,
407+ swarm_ylim = swarm_ylim ,
408+ og_xlim_raw = og_xlim_raw ,
409+ og_ylim_raw = og_ylim_raw ,
410+ )
409411
410412 else :
411413 # For Cumming Plots only.
@@ -426,110 +428,23 @@ def effectsize_df_plotter(effectsize_df, **plot_kwargs):
426428 redraw_axes_kwargs = redraw_axes_kwargs ,
427429 ticks_to_skip_contrast = ticks_to_skip_contrast ,
428430 )
429-
430-
431- if show_delta2 or show_mini_meta :
432- ylim = contrast_axes .get_ylim ()
433- redraw_axes_kwargs ["y" ] = ylim [0 ]
434- x_ticks = contrast_axes .get_xticks ()
435- contrast_axes .hlines (xmin = x_ticks [- 2 ], xmax = x_ticks [- 1 ], ** redraw_axes_kwargs )
436- del redraw_axes_kwargs ["y" ]
437-
438- # Set raw axes y-label.
439- swarm_label = plot_kwargs ["swarm_label" ]
440- if swarm_label is None and yvar is None :
441- swarm_label = "value"
442- elif swarm_label is None and yvar is not None :
443- swarm_label = yvar
444-
445- bar_label = plot_kwargs ["bar_label" ]
446- if bar_label is None and effect_size_type != "cohens_h" :
447- bar_label = "proportion of success"
448- elif bar_label is None and effect_size_type == "cohens_h" :
449- bar_label = "value"
450-
451- # Place contrast axes y-label.
452- contrast_label_dict = {
453- "mean_diff" : "mean difference" ,
454- "median_diff" : "median difference" ,
455- "cohens_d" : "Cohen's d" ,
456- "hedges_g" : "Hedges' g" ,
457- "cliffs_delta" : "Cliff's delta" ,
458- "cohens_h" : "Cohen's h" ,
459- "delta_g" : "mean difference" ,
460- }
461-
462- if proportional and effect_size_type != "cohens_h" :
463- default_contrast_label = "proportion difference"
464- elif effect_size_type == "delta_g" :
465- default_contrast_label = "Hedges' g"
466- else :
467- default_contrast_label = contrast_label_dict [effectsize_df .effect_size ]
468-
469- if plot_kwargs ["contrast_label" ] is None :
470- if is_paired :
471- contrast_label = "paired\n {}" .format (default_contrast_label )
472- else :
473- contrast_label = default_contrast_label
474- contrast_label = contrast_label .capitalize ()
475- else :
476- contrast_label = plot_kwargs ["contrast_label" ]
477-
478- if plot_kwargs ["fontsize_rawylabel" ] is not None :
479- fontsize_rawylabel = plot_kwargs ["fontsize_rawylabel" ]
480- if plot_kwargs ["fontsize_contrastylabel" ] is not None :
481- fontsize_contrastylabel = plot_kwargs ["fontsize_contrastylabel" ]
482- if plot_kwargs ["fontsize_delta2label" ] is not None :
483- fontsize_delta2label = plot_kwargs ["fontsize_delta2label" ]
484-
485- contrast_axes .set_ylabel (contrast_label , fontsize = fontsize_contrastylabel )
486- if float_contrast :
487- contrast_axes .yaxis .set_label_position ("right" )
488-
489- # Set the rawdata axes labels appropriately
490- if not proportional :
491- rawdata_axes .set_ylabel (swarm_label , fontsize = fontsize_rawylabel )
492- else :
493- rawdata_axes .set_ylabel (bar_label , fontsize = fontsize_rawylabel )
494- rawdata_axes .set_xlabel ("" )
495-
496- # Because we turned the axes frame off, we also need to draw back
497- # the y-spine for both axes.
498- if not float_contrast :
499- rawdata_axes .set_xlim (contrast_axes .get_xlim ())
500- og_xlim_raw = rawdata_axes .get_xlim ()
501- rawdata_axes .vlines (
502- og_xlim_raw [0 ], og_ylim_raw [0 ], og_ylim_raw [1 ], ** redraw_axes_kwargs
503- )
504-
505- og_xlim_contrast = contrast_axes .get_xlim ()
506-
507- if float_contrast :
508- xpos = og_xlim_contrast [1 ]
509- else :
510- xpos = og_xlim_contrast [0 ]
511-
512- og_ylim_contrast = contrast_axes .get_ylim ()
513- contrast_axes .vlines (
514- xpos , og_ylim_contrast [0 ], og_ylim_contrast [1 ], ** redraw_axes_kwargs
515- )
516-
517- if show_delta2 :
518- if plot_kwargs ["delta2_label" ] is not None :
519- delta2_label = plot_kwargs ["delta2_label" ]
520- elif effect_size == "mean_diff" :
521- delta2_label = "delta - delta"
522- else :
523- delta2_label = "deltas' g"
524- delta2_axes = contrast_axes .twinx ()
525- delta2_axes .set_frame_on (False )
526- delta2_axes .set_ylabel (delta2_label , fontsize = fontsize_delta2label )
527- og_xlim_delta = contrast_axes .get_xlim ()
528- og_ylim_delta = contrast_axes .get_ylim ()
529- delta2_axes .set_ylim (og_ylim_delta )
530- delta2_axes .vlines (
531- og_xlim_delta [1 ], og_ylim_delta [0 ], og_ylim_delta [1 ], ** redraw_axes_kwargs
532- )
431+
432+ # General plotting changes
433+ General_Plot_Aesthetic_Adjustments (show_delta2 = show_delta2 ,
434+ show_mini_meta = show_mini_meta ,
435+ contrast_axes = contrast_axes ,
436+ redraw_axes_kwargs = redraw_axes_kwargs ,
437+ plot_kwargs = plot_kwargs ,
438+ yvar = yvar ,
439+ effect_size_type = effect_size_type ,
440+ proportional = proportional ,
441+ effectsize_df = effectsize_df ,
442+ is_paired = is_paired ,
443+ float_contrast = float_contrast ,
444+ rawdata_axes = rawdata_axes ,
445+ og_ylim_raw = og_ylim_raw ,
446+ effect_size = effect_size ,
447+ )
533448
534449 ################################################### GRIDKEY WIP
535450 # if gridkey_rows is None, skip everything here
0 commit comments