Skip to content

Commit

Permalink
Gridkey fixes, function to show es on contrast plot
Browse files Browse the repository at this point in the history
  • Loading branch information
maiyishan committed Jun 3, 2023
1 parent 065ccd6 commit bcfe57c
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 12 deletions.
4 changes: 4 additions & 0 deletions dabest/_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2445,6 +2445,10 @@ def plot(self, color_col=None,
fig_size=None,
dpi=100,
ax=None,

contrast_show_es = False,
es_sf = 2,
es_fontsize = 10,

gridkey_rows=None,
gridkey_merge_pairs = False,
Expand Down
52 changes: 46 additions & 6 deletions dabest/plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
gridkey_show_Ns = plot_kwargs["gridkey_show_Ns"]
gridkey_show_es = plot_kwargs["gridkey_show_es"]

if gridkey_rows == None:
gridkey_show_Ns = False
gridkey_show_es = False

################################################### END GRIDKEY WIP - extracting kwargs

# Group summaries kwargs.
Expand Down Expand Up @@ -314,11 +318,14 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
###################### GRIDKEY HSPACE ALTERATION

# Sets hspace for cummings plots if gridkey is shown.
if gridkey_rows is not None:
if gridkey_rows != None:
h_space_cummings = 0.1
else:
h_space_cummings = 0.3

##### TESTING SOME SHIT


###################### END GRIDKEY HSPACE ALTERATION

if plot_kwargs["ax"] is not None:
Expand Down Expand Up @@ -447,6 +454,7 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
slopegraph_kwargs['label'] = color_key

rawdata_axes.plot(x_points, y_points, **slopegraph_kwargs)

x_start = x_start + grp_count
# Set the tick labels, because the slopegraph plotting doesn't.
rawdata_axes.set_xticks(np.arange(0, len(temp_all_plot_groups)))
Expand Down Expand Up @@ -666,6 +674,37 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
color=ytick_color,
markersize=es_marker_size)

################## SHOW ES ON CONTRAST PLOT WIP

contrast_show_es = plot_kwargs["contrast_show_es"]
es_sf = plot_kwargs['es_sf']
es_fontsize = plot_kwargs['es_fontsize']

if gridkey_show_es == True:
contrast_show_es = False



effsize_for_print = current_effsize

printed_es = np.format_float_positional(effsize_for_print,
precision=es_sf,
sign=True,
trim= 'k',
min_digits = es_sf)
if contrast_show_es == True:
if effsize_for_print < 0:
textoffset = 10
else:
textoffset = 15
contrast_axes.annotate(text=printed_es,
xy = (tick, effsize_for_print),
xytext = (-textoffset-len(printed_es)*es_fontsize/2,-es_fontsize/2),
textcoords = "offset points",
**{ "fontsize" : es_fontsize })

################## SHOW ES ON CONTRAST PLOT END

# Plot the confidence interval.
contrast_axes.plot([tick, tick],
[current_ci_low, current_ci_high],
Expand Down Expand Up @@ -1166,7 +1205,7 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
if isinstance(gridkey_rows, list) is False:
raise TypeError("gridkey_rows must be a list.")
elif len(gridkey_rows) == 0:
raise ValueError("gridkey_rows cannot be an empty list.")
warnings.warn("gridkey_rows is an empty list.")


# raise Warning if an item in gridkey_rows is not contained in any idx
Expand Down Expand Up @@ -1214,10 +1253,11 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
for i in enumerate(groups_for_gridkey):
if i[1] in results_list:
curr_esval = results.loc[results["test"] == i[1]]["difference"].iloc[0]
if curr_esval >= 0:
curr_esval_str = "+" + str("%.2f" % curr_esval)
else:
curr_esval_str = str("%.2f" % curr_esval)
curr_esval_str = np.format_float_positional(curr_esval,
precision=es_sf,
sign=True,
trim= 'k',
min_digits = es_sf)
effsize_list.append(curr_esval_str)
else:
effsize_list.append("-")
Expand Down
4 changes: 4 additions & 0 deletions nbs/API/class.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3257,6 +3257,10 @@
" fig_size=None,\n",
" dpi=100,\n",
" ax=None,\n",
" \n",
" contrast_show_es = False,\n",
" es_sf = 2,\n",
" es_fontsize = 10,\n",
" \n",
" gridkey_rows=None,\n",
" gridkey_merge_pairs = False,\n",
Expand Down
52 changes: 46 additions & 6 deletions nbs/API/plotter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,10 @@
" gridkey_show_Ns = plot_kwargs[\"gridkey_show_Ns\"]\n",
" gridkey_show_es = plot_kwargs[\"gridkey_show_es\"]\n",
" \n",
" if gridkey_rows == None:\n",
" gridkey_show_Ns = False\n",
" gridkey_show_es = False\n",
" \n",
"################################################### END GRIDKEY WIP - extracting kwargs\n",
"\n",
" # Group summaries kwargs.\n",
Expand Down Expand Up @@ -364,11 +368,14 @@
"###################### GRIDKEY HSPACE ALTERATION\n",
"\n",
" # Sets hspace for cummings plots if gridkey is shown.\n",
" if gridkey_rows is not None:\n",
" if gridkey_rows != None:\n",
" h_space_cummings = 0.1\n",
" else:\n",
" h_space_cummings = 0.3\n",
" \n",
" ##### TESTING SOME SHIT\n",
" \n",
" \n",
"###################### END GRIDKEY HSPACE ALTERATION \n",
" \n",
" if plot_kwargs[\"ax\"] is not None:\n",
Expand Down Expand Up @@ -497,6 +504,7 @@
" slopegraph_kwargs['label'] = color_key\n",
"\n",
" rawdata_axes.plot(x_points, y_points, **slopegraph_kwargs)\n",
" \n",
" x_start = x_start + grp_count\n",
" # Set the tick labels, because the slopegraph plotting doesn't.\n",
" rawdata_axes.set_xticks(np.arange(0, len(temp_all_plot_groups)))\n",
Expand Down Expand Up @@ -716,6 +724,37 @@
" color=ytick_color,\n",
" markersize=es_marker_size)\n",
" \n",
"################## SHOW ES ON CONTRAST PLOT WIP \n",
"\n",
" contrast_show_es = plot_kwargs[\"contrast_show_es\"]\n",
" es_sf = plot_kwargs['es_sf']\n",
" es_fontsize = plot_kwargs['es_fontsize']\n",
" \n",
" if gridkey_show_es == True:\n",
" contrast_show_es = False\n",
" \n",
"\n",
" \n",
" effsize_for_print = current_effsize\n",
" \n",
" printed_es = np.format_float_positional(effsize_for_print,\n",
" precision=es_sf,\n",
" sign=True,\n",
" trim= 'k',\n",
" min_digits = es_sf)\n",
" if contrast_show_es == True:\n",
" if effsize_for_print < 0:\n",
" textoffset = 10\n",
" else:\n",
" textoffset = 15\n",
" contrast_axes.annotate(text=printed_es, \n",
" xy = (tick, effsize_for_print),\n",
" xytext = (-textoffset-len(printed_es)*es_fontsize/2,-es_fontsize/2),\n",
" textcoords = \"offset points\",\n",
" **{ \"fontsize\" : es_fontsize })\n",
" \n",
"################## SHOW ES ON CONTRAST PLOT END \n",
" \n",
" # Plot the confidence interval.\n",
" contrast_axes.plot([tick, tick],\n",
" [current_ci_low, current_ci_high],\n",
Expand Down Expand Up @@ -1216,7 +1255,7 @@
" if isinstance(gridkey_rows, list) is False:\n",
" raise TypeError(\"gridkey_rows must be a list.\")\n",
" elif len(gridkey_rows) == 0:\n",
" raise ValueError(\"gridkey_rows cannot be an empty list.\")\n",
" warnings.warn(\"gridkey_rows is an empty list.\")\n",
" \n",
" \n",
" # raise Warning if an item in gridkey_rows is not contained in any idx\n",
Expand Down Expand Up @@ -1264,10 +1303,11 @@
" for i in enumerate(groups_for_gridkey):\n",
" if i[1] in results_list:\n",
" curr_esval = results.loc[results[\"test\"] == i[1]][\"difference\"].iloc[0]\n",
" if curr_esval >= 0: \n",
" curr_esval_str = \"+\" + str(\"%.2f\" % curr_esval)\n",
" else:\n",
" curr_esval_str = str(\"%.2f\" % curr_esval)\n",
" curr_esval_str = np.format_float_positional(curr_esval,\n",
" precision=es_sf,\n",
" sign=True,\n",
" trim= 'k',\n",
" min_digits = es_sf)\n",
" effsize_list.append(curr_esval_str)\n",
" else:\n",
" effsize_list.append(\"-\")\n",
Expand Down

0 comments on commit bcfe57c

Please sign in to comment.