Skip to content

Commit bcfe57c

Browse files
committed
Gridkey fixes, function to show es on contrast plot
1 parent 065ccd6 commit bcfe57c

4 files changed

Lines changed: 100 additions & 12 deletions

File tree

dabest/_classes.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2445,6 +2445,10 @@ def plot(self, color_col=None,
24452445
fig_size=None,
24462446
dpi=100,
24472447
ax=None,
2448+
2449+
contrast_show_es = False,
2450+
es_sf = 2,
2451+
es_fontsize = 10,
24482452

24492453
gridkey_rows=None,
24502454
gridkey_merge_pairs = False,

dabest/plotter.py

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,10 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
186186
gridkey_show_Ns = plot_kwargs["gridkey_show_Ns"]
187187
gridkey_show_es = plot_kwargs["gridkey_show_es"]
188188

189+
if gridkey_rows == None:
190+
gridkey_show_Ns = False
191+
gridkey_show_es = False
192+
189193
################################################### END GRIDKEY WIP - extracting kwargs
190194

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

316320
# Sets hspace for cummings plots if gridkey is shown.
317-
if gridkey_rows is not None:
321+
if gridkey_rows != None:
318322
h_space_cummings = 0.1
319323
else:
320324
h_space_cummings = 0.3
321325

326+
##### TESTING SOME SHIT
327+
328+
322329
###################### END GRIDKEY HSPACE ALTERATION
323330

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

449456
rawdata_axes.plot(x_points, y_points, **slopegraph_kwargs)
457+
450458
x_start = x_start + grp_count
451459
# Set the tick labels, because the slopegraph plotting doesn't.
452460
rawdata_axes.set_xticks(np.arange(0, len(temp_all_plot_groups)))
@@ -666,6 +674,37 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
666674
color=ytick_color,
667675
markersize=es_marker_size)
668676

677+
################## SHOW ES ON CONTRAST PLOT WIP
678+
679+
contrast_show_es = plot_kwargs["contrast_show_es"]
680+
es_sf = plot_kwargs['es_sf']
681+
es_fontsize = plot_kwargs['es_fontsize']
682+
683+
if gridkey_show_es == True:
684+
contrast_show_es = False
685+
686+
687+
688+
effsize_for_print = current_effsize
689+
690+
printed_es = np.format_float_positional(effsize_for_print,
691+
precision=es_sf,
692+
sign=True,
693+
trim= 'k',
694+
min_digits = es_sf)
695+
if contrast_show_es == True:
696+
if effsize_for_print < 0:
697+
textoffset = 10
698+
else:
699+
textoffset = 15
700+
contrast_axes.annotate(text=printed_es,
701+
xy = (tick, effsize_for_print),
702+
xytext = (-textoffset-len(printed_es)*es_fontsize/2,-es_fontsize/2),
703+
textcoords = "offset points",
704+
**{ "fontsize" : es_fontsize })
705+
706+
################## SHOW ES ON CONTRAST PLOT END
707+
669708
# Plot the confidence interval.
670709
contrast_axes.plot([tick, tick],
671710
[current_ci_low, current_ci_high],
@@ -1166,7 +1205,7 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
11661205
if isinstance(gridkey_rows, list) is False:
11671206
raise TypeError("gridkey_rows must be a list.")
11681207
elif len(gridkey_rows) == 0:
1169-
raise ValueError("gridkey_rows cannot be an empty list.")
1208+
warnings.warn("gridkey_rows is an empty list.")
11701209

11711210

11721211
# raise Warning if an item in gridkey_rows is not contained in any idx
@@ -1214,10 +1253,11 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
12141253
for i in enumerate(groups_for_gridkey):
12151254
if i[1] in results_list:
12161255
curr_esval = results.loc[results["test"] == i[1]]["difference"].iloc[0]
1217-
if curr_esval >= 0:
1218-
curr_esval_str = "+" + str("%.2f" % curr_esval)
1219-
else:
1220-
curr_esval_str = str("%.2f" % curr_esval)
1256+
curr_esval_str = np.format_float_positional(curr_esval,
1257+
precision=es_sf,
1258+
sign=True,
1259+
trim= 'k',
1260+
min_digits = es_sf)
12211261
effsize_list.append(curr_esval_str)
12221262
else:
12231263
effsize_list.append("-")

nbs/API/class.ipynb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3257,6 +3257,10 @@
32573257
" fig_size=None,\n",
32583258
" dpi=100,\n",
32593259
" ax=None,\n",
3260+
" \n",
3261+
" contrast_show_es = False,\n",
3262+
" es_sf = 2,\n",
3263+
" es_fontsize = 10,\n",
32603264
" \n",
32613265
" gridkey_rows=None,\n",
32623266
" gridkey_merge_pairs = False,\n",

nbs/API/plotter.ipynb

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@
236236
" gridkey_show_Ns = plot_kwargs[\"gridkey_show_Ns\"]\n",
237237
" gridkey_show_es = plot_kwargs[\"gridkey_show_es\"]\n",
238238
" \n",
239+
" if gridkey_rows == None:\n",
240+
" gridkey_show_Ns = False\n",
241+
" gridkey_show_es = False\n",
242+
" \n",
239243
"################################################### END GRIDKEY WIP - extracting kwargs\n",
240244
"\n",
241245
" # Group summaries kwargs.\n",
@@ -364,11 +368,14 @@
364368
"###################### GRIDKEY HSPACE ALTERATION\n",
365369
"\n",
366370
" # Sets hspace for cummings plots if gridkey is shown.\n",
367-
" if gridkey_rows is not None:\n",
371+
" if gridkey_rows != None:\n",
368372
" h_space_cummings = 0.1\n",
369373
" else:\n",
370374
" h_space_cummings = 0.3\n",
371375
" \n",
376+
" ##### TESTING SOME SHIT\n",
377+
" \n",
378+
" \n",
372379
"###################### END GRIDKEY HSPACE ALTERATION \n",
373380
" \n",
374381
" if plot_kwargs[\"ax\"] is not None:\n",
@@ -497,6 +504,7 @@
497504
" slopegraph_kwargs['label'] = color_key\n",
498505
"\n",
499506
" rawdata_axes.plot(x_points, y_points, **slopegraph_kwargs)\n",
507+
" \n",
500508
" x_start = x_start + grp_count\n",
501509
" # Set the tick labels, because the slopegraph plotting doesn't.\n",
502510
" rawdata_axes.set_xticks(np.arange(0, len(temp_all_plot_groups)))\n",
@@ -716,6 +724,37 @@
716724
" color=ytick_color,\n",
717725
" markersize=es_marker_size)\n",
718726
" \n",
727+
"################## SHOW ES ON CONTRAST PLOT WIP \n",
728+
"\n",
729+
" contrast_show_es = plot_kwargs[\"contrast_show_es\"]\n",
730+
" es_sf = plot_kwargs['es_sf']\n",
731+
" es_fontsize = plot_kwargs['es_fontsize']\n",
732+
" \n",
733+
" if gridkey_show_es == True:\n",
734+
" contrast_show_es = False\n",
735+
" \n",
736+
"\n",
737+
" \n",
738+
" effsize_for_print = current_effsize\n",
739+
" \n",
740+
" printed_es = np.format_float_positional(effsize_for_print,\n",
741+
" precision=es_sf,\n",
742+
" sign=True,\n",
743+
" trim= 'k',\n",
744+
" min_digits = es_sf)\n",
745+
" if contrast_show_es == True:\n",
746+
" if effsize_for_print < 0:\n",
747+
" textoffset = 10\n",
748+
" else:\n",
749+
" textoffset = 15\n",
750+
" contrast_axes.annotate(text=printed_es, \n",
751+
" xy = (tick, effsize_for_print),\n",
752+
" xytext = (-textoffset-len(printed_es)*es_fontsize/2,-es_fontsize/2),\n",
753+
" textcoords = \"offset points\",\n",
754+
" **{ \"fontsize\" : es_fontsize })\n",
755+
" \n",
756+
"################## SHOW ES ON CONTRAST PLOT END \n",
757+
" \n",
719758
" # Plot the confidence interval.\n",
720759
" contrast_axes.plot([tick, tick],\n",
721760
" [current_ci_low, current_ci_high],\n",
@@ -1216,7 +1255,7 @@
12161255
" if isinstance(gridkey_rows, list) is False:\n",
12171256
" raise TypeError(\"gridkey_rows must be a list.\")\n",
12181257
" elif len(gridkey_rows) == 0:\n",
1219-
" raise ValueError(\"gridkey_rows cannot be an empty list.\")\n",
1258+
" warnings.warn(\"gridkey_rows is an empty list.\")\n",
12201259
" \n",
12211260
" \n",
12221261
" # raise Warning if an item in gridkey_rows is not contained in any idx\n",
@@ -1264,10 +1303,11 @@
12641303
" for i in enumerate(groups_for_gridkey):\n",
12651304
" if i[1] in results_list:\n",
12661305
" curr_esval = results.loc[results[\"test\"] == i[1]][\"difference\"].iloc[0]\n",
1267-
" if curr_esval >= 0: \n",
1268-
" curr_esval_str = \"+\" + str(\"%.2f\" % curr_esval)\n",
1269-
" else:\n",
1270-
" curr_esval_str = str(\"%.2f\" % curr_esval)\n",
1306+
" curr_esval_str = np.format_float_positional(curr_esval,\n",
1307+
" precision=es_sf,\n",
1308+
" sign=True,\n",
1309+
" trim= 'k',\n",
1310+
" min_digits = es_sf)\n",
12711311
" effsize_list.append(curr_esval_str)\n",
12721312
" else:\n",
12731313
" effsize_list.append(\"-\")\n",

0 commit comments

Comments
 (0)