Skip to content

Commit

Permalink
Trimming down plotter
Browse files Browse the repository at this point in the history
  • Loading branch information
JAnns98 committed Sep 12, 2024
1 parent 6f59874 commit ddeefa7
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 30 deletions.
17 changes: 8 additions & 9 deletions dabest/misc_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ def get_params(effectsize_df, plot_kwargs):
plot_kwargs : dict
Kwargs passed to the plot function.
"""
face_color = plot_kwargs["face_color"]

if plot_kwargs["face_color"] is None:
face_color = "white"

dabest_obj = effectsize_df.dabest_obj
plot_data = effectsize_df._plot_data
xvar = effectsize_df.xvar
Expand All @@ -100,7 +95,6 @@ def get_params(effectsize_df, plot_kwargs):
mini_meta = effectsize_df.mini_meta
effect_size = effectsize_df.effect_size
proportional = effectsize_df.proportional

all_plot_groups = dabest_obj._all_plot_groups
idx = dabest_obj.idx

Expand Down Expand Up @@ -144,8 +138,7 @@ def get_params(effectsize_df, plot_kwargs):
if err_color is None:
err_color = "black"


return (face_color, dabest_obj, plot_data, xvar, yvar, is_paired, effect_size, proportional, all_plot_groups, idx,
return (dabest_obj, plot_data, xvar, yvar, is_paired, effect_size, proportional, all_plot_groups, idx,
show_delta2, show_mini_meta, float_contrast, show_pairs, effect_size_type, group_summaries, err_color)

def get_kwargs(plot_kwargs, ytick_color):
Expand Down Expand Up @@ -381,8 +374,13 @@ def get_color_palette(plot_kwargs, plot_data, xvar, show_pairs):
bar_color, plot_palette_bar, plot_palette_contrast, plot_palette_sankey)

def initialize_fig(plot_kwargs, dabest_obj, show_delta2, show_mini_meta, is_paired, show_pairs, proportional,
float_contrast, face_color):
float_contrast):
# Params
fig_size = plot_kwargs["fig_size"]
face_color = plot_kwargs["face_color"]
if plot_kwargs["face_color"] is None:
face_color = "white"

if fig_size is None:
all_groups_count = np.sum([len(i) for i in dabest_obj.idx])
# Increase the width for delta-delta graph
Expand Down Expand Up @@ -497,6 +495,7 @@ def get_plot_groups(is_paired, idx, proportional, all_plot_groups):
# Determine temp_all_plot_groups based on proportional condition
plot_groups = [item for i in temp_idx for item in i]
temp_all_plot_groups = all_plot_groups if not proportional else plot_groups

return temp_idx, temp_all_plot_groups


Expand Down
9 changes: 3 additions & 6 deletions dabest/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def effectsize_df_plotter(effectsize_df, **plot_kwargs):
ytick_color = plt.rcParams["ytick.color"]

# Extract parameters and set kwargs
(face_color, dabest_obj, plot_data, xvar, yvar, is_paired, effect_size,
(dabest_obj, plot_data, xvar, yvar, is_paired, effect_size,
proportional, all_plot_groups, idx, show_delta2, show_mini_meta,
float_contrast, show_pairs, effect_size_type, group_summaries, err_color) = get_params(
effectsize_df=effectsize_df,
Expand All @@ -124,13 +124,11 @@ def effectsize_df_plotter(effectsize_df, **plot_kwargs):
# We also need to extract the `sankey` and `flow` from the kwargs for plotter.py
# to use for varying different kinds of paired proportional plots
# We also don't want to pop the parameter from the kwargs
sankey = sankey_kwargs["sankey"]
flow = sankey_kwargs["flow"]
one_sankey = (
False if is_paired is not None else None
) # Flag to indicate if only one sankey is plotted.
two_col_sankey = (
True if proportional and not one_sankey and sankey and not flow else False
True if proportional and not one_sankey and sankey_kwargs["sankey"] and not sankey_kwargs["flow"] else False
)

# Extract Color palette
Expand All @@ -152,8 +150,7 @@ def effectsize_df_plotter(effectsize_df, **plot_kwargs):
is_paired=is_paired,
show_pairs=show_pairs,
proportional=proportional,
float_contrast=float_contrast,
face_color=face_color,
float_contrast=float_contrast,
)

# Plotting the rawdata.
Expand Down
17 changes: 8 additions & 9 deletions nbs/API/misc_tools.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,6 @@
" plot_kwargs : dict\n",
" Kwargs passed to the plot function.\n",
" \"\"\"\n",
" face_color = plot_kwargs[\"face_color\"]\n",
"\n",
" if plot_kwargs[\"face_color\"] is None:\n",
" face_color = \"white\"\n",
"\n",
" dabest_obj = effectsize_df.dabest_obj\n",
" plot_data = effectsize_df._plot_data\n",
" xvar = effectsize_df.xvar\n",
Expand All @@ -155,7 +150,6 @@
" mini_meta = effectsize_df.mini_meta\n",
" effect_size = effectsize_df.effect_size\n",
" proportional = effectsize_df.proportional\n",
"\n",
" all_plot_groups = dabest_obj._all_plot_groups\n",
" idx = dabest_obj.idx\n",
"\n",
Expand Down Expand Up @@ -199,8 +193,7 @@
" if err_color is None: \n",
" err_color = \"black\"\n",
" \n",
"\n",
" return (face_color, dabest_obj, plot_data, xvar, yvar, is_paired, effect_size, proportional, all_plot_groups, idx, \n",
" return (dabest_obj, plot_data, xvar, yvar, is_paired, effect_size, proportional, all_plot_groups, idx, \n",
" show_delta2, show_mini_meta, float_contrast, show_pairs, effect_size_type, group_summaries, err_color)\n",
"\n",
"def get_kwargs(plot_kwargs, ytick_color):\n",
Expand Down Expand Up @@ -436,8 +429,13 @@
" bar_color, plot_palette_bar, plot_palette_contrast, plot_palette_sankey)\n",
"\n",
"def initialize_fig(plot_kwargs, dabest_obj, show_delta2, show_mini_meta, is_paired, show_pairs, proportional,\n",
" float_contrast, face_color):\n",
" float_contrast):\n",
" # Params\n",
" fig_size = plot_kwargs[\"fig_size\"]\n",
" face_color = plot_kwargs[\"face_color\"]\n",
" if plot_kwargs[\"face_color\"] is None:\n",
" face_color = \"white\"\n",
"\n",
" if fig_size is None:\n",
" all_groups_count = np.sum([len(i) for i in dabest_obj.idx])\n",
" # Increase the width for delta-delta graph\n",
Expand Down Expand Up @@ -552,6 +550,7 @@
" # Determine temp_all_plot_groups based on proportional condition\n",
" plot_groups = [item for i in temp_idx for item in i]\n",
" temp_all_plot_groups = all_plot_groups if not proportional else plot_groups\n",
" \n",
" return temp_idx, temp_all_plot_groups\n",
"\n",
"\n",
Expand Down
9 changes: 3 additions & 6 deletions nbs/API/plotter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
" ytick_color = plt.rcParams[\"ytick.color\"]\n",
"\n",
" # Extract parameters and set kwargs\n",
" (face_color, dabest_obj, plot_data, xvar, yvar, is_paired, effect_size, \n",
" (dabest_obj, plot_data, xvar, yvar, is_paired, effect_size, \n",
" proportional, all_plot_groups, idx, show_delta2, show_mini_meta, \n",
" float_contrast, show_pairs, effect_size_type, group_summaries, err_color) = get_params(\n",
" effectsize_df=effectsize_df, \n",
Expand All @@ -183,13 +183,11 @@
" # We also need to extract the `sankey` and `flow` from the kwargs for plotter.py\n",
" # to use for varying different kinds of paired proportional plots\n",
" # We also don't want to pop the parameter from the kwargs\n",
" sankey = sankey_kwargs[\"sankey\"]\n",
" flow = sankey_kwargs[\"flow\"]\n",
" one_sankey = (\n",
" False if is_paired is not None else None\n",
" ) # Flag to indicate if only one sankey is plotted.\n",
" two_col_sankey = (\n",
" True if proportional and not one_sankey and sankey and not flow else False\n",
" True if proportional and not one_sankey and sankey_kwargs[\"sankey\"] and not sankey_kwargs[\"flow\"] else False\n",
" )\n",
"\n",
" # Extract Color palette\n",
Expand All @@ -211,8 +209,7 @@
" is_paired=is_paired, \n",
" show_pairs=show_pairs, \n",
" proportional=proportional, \n",
" float_contrast=float_contrast, \n",
" face_color=face_color, \n",
" float_contrast=float_contrast,\n",
" )\n",
" \n",
" # Plotting the rawdata.\n",
Expand Down

0 comments on commit ddeefa7

Please sign in to comment.