Skip to content

Commit f41f3d5

Browse files
committed
delta points on contrast axis WIP
1 parent bcfe57c commit f41f3d5

4 files changed

Lines changed: 132 additions & 12 deletions

File tree

dabest/_classes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2450,6 +2450,8 @@ def plot(self, color_col=None,
24502450
es_sf = 2,
24512451
es_fontsize = 10,
24522452

2453+
contrast_show_deltas = True,
2454+
24532455
gridkey_rows=None,
24542456
gridkey_merge_pairs = False,
24552457
gridkey_show_Ns = True,

dabest/plotter.py

Lines changed: 60 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
179179
plot_kwargs["legend_kwargs"])
180180

181181

182-
################################################### GRIDKEY WIP - extracting kwargs
182+
################################################### GRIDKEY WIP - extracting arguments
183183

184184
gridkey_rows = plot_kwargs["gridkey_rows"]
185185
gridkey_merge_pairs = plot_kwargs["gridkey_merge_pairs"]
@@ -190,7 +190,7 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
190190
gridkey_show_Ns = False
191191
gridkey_show_es = False
192192

193-
################################################### END GRIDKEY WIP - extracting kwargs
193+
################################################### END GRIDKEY WIP - extracting arguments
194194

195195
# Group summaries kwargs.
196196
gs_default = {'mean_sd', 'median_quartiles', None}
@@ -322,8 +322,6 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
322322
h_space_cummings = 0.1
323323
else:
324324
h_space_cummings = 0.3
325-
326-
##### TESTING SOME SHIT
327325

328326

329327
###################### END GRIDKEY HSPACE ALTERATION
@@ -453,9 +451,62 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
453451
slopegraph_kwargs['color'] = plot_palette_raw[color_key]
454452
slopegraph_kwargs['label'] = color_key
455453

456-
rawdata_axes.plot(x_points, y_points, **slopegraph_kwargs)
454+
rawdata_axes.plot(x_points, y_points, **slopegraph_kwargs)
455+
457456

458457
x_start = x_start + grp_count
458+
459+
##################### DELTA PTS ON CONTRAST PLOT WIP
460+
461+
contrast_show_deltas = plot_kwargs["contrast_show_deltas"]
462+
463+
if is_paired == None:
464+
contrast_show_deltas = False
465+
466+
if contrast_show_deltas == True:
467+
468+
trans = plt.gca().transData
469+
470+
delta_plot_data_temp = plot_data.copy()
471+
delta_id_col = dabest_obj.id_col
472+
if color_col != None:
473+
delta_plot_data = delta_plot_data_temp[[xvar, yvar, delta_id_col, color_col]]
474+
deltapts_args = {"hue" : color_col,
475+
"palette" : plot_palette_raw,
476+
"marker" : "^",
477+
"alpha" : 0.5}
478+
479+
else:
480+
delta_plot_data = delta_plot_data_temp[[xvar, yvar, delta_id_col]]
481+
deltapts_args = {"color" : "k",
482+
"marker" : "^",
483+
"alpha" : 0.5}
484+
485+
final_deltas = pd.DataFrame()
486+
for i in idx:
487+
for j in i:
488+
if i.index(j) != 0:
489+
temp_df_exp = delta_plot_data[delta_plot_data[xvar].str.contains(j)].reset_index(drop=True)
490+
if is_paired == "baseline":
491+
temp_df_cont = delta_plot_data[delta_plot_data[xvar].str.contains(i[0])].reset_index(drop=True)
492+
elif is_paired == "sequential":
493+
temp_df_cont = delta_plot_data[delta_plot_data[xvar].str.contains(i[i.index(j) - 1])].reset_index(drop=True)
494+
delta_df = temp_df_exp.copy()
495+
delta_df[yvar] = temp_df_exp[yvar] - temp_df_cont[yvar]
496+
final_deltas = pd.concat([final_deltas, delta_df])
497+
498+
499+
# Plot the raw data as a swarmplot.
500+
deltapts_plot = sns.swarmplot(data=final_deltas, x=xvar, y=yvar,
501+
ax=contrast_axes,
502+
order=all_plot_groups,
503+
zorder=2,
504+
**deltapts_args)
505+
contrast_axes.legend().set_visible(False)
506+
507+
##################### DELTA PTS ON CONTRAST PLOT END
508+
509+
459510
# Set the tick labels, because the slopegraph plotting doesn't.
460511
rawdata_axes.set_xticks(np.arange(0, len(temp_all_plot_groups)))
461512
rawdata_axes.set_xticklabels(temp_all_plot_groups)
@@ -1293,7 +1344,10 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
12931344
contrast_axes.get_xaxis().set_visible(False)
12941345

12951346
####################################################### END GRIDKEY MAIN CODE WIP
1296-
1347+
1348+
1349+
1350+
12971351
# Make sure no stray ticks appear!
12981352
rawdata_axes.xaxis.set_ticks_position('bottom')
12991353
rawdata_axes.yaxis.set_ticks_position('left')

nbs/API/class.ipynb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3262,6 +3262,8 @@
32623262
" es_sf = 2,\n",
32633263
" es_fontsize = 10,\n",
32643264
" \n",
3265+
" contrast_show_deltas = True,\n",
3266+
" \n",
32653267
" gridkey_rows=None,\n",
32663268
" gridkey_merge_pairs = False,\n",
32673269
" gridkey_show_Ns = True,\n",

nbs/API/plotter.ipynb

Lines changed: 68 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@
229229
" plot_kwargs[\"legend_kwargs\"])\n",
230230
" \n",
231231
" \n",
232-
"################################################### GRIDKEY WIP - extracting kwargs \n",
232+
"################################################### GRIDKEY WIP - extracting arguments \n",
233233
" \n",
234234
" gridkey_rows = plot_kwargs[\"gridkey_rows\"]\n",
235235
" gridkey_merge_pairs = plot_kwargs[\"gridkey_merge_pairs\"]\n",
@@ -240,7 +240,7 @@
240240
" gridkey_show_Ns = False\n",
241241
" gridkey_show_es = False\n",
242242
" \n",
243-
"################################################### END GRIDKEY WIP - extracting kwargs\n",
243+
"################################################### END GRIDKEY WIP - extracting arguments\n",
244244
"\n",
245245
" # Group summaries kwargs.\n",
246246
" gs_default = {'mean_sd', 'median_quartiles', None}\n",
@@ -372,8 +372,6 @@
372372
" h_space_cummings = 0.1\n",
373373
" else:\n",
374374
" h_space_cummings = 0.3\n",
375-
" \n",
376-
" ##### TESTING SOME SHIT\n",
377375
" \n",
378376
" \n",
379377
"###################### END GRIDKEY HSPACE ALTERATION \n",
@@ -503,9 +501,62 @@
503501
" slopegraph_kwargs['color'] = plot_palette_raw[color_key]\n",
504502
" slopegraph_kwargs['label'] = color_key\n",
505503
"\n",
506-
" rawdata_axes.plot(x_points, y_points, **slopegraph_kwargs)\n",
504+
" rawdata_axes.plot(x_points, y_points, **slopegraph_kwargs) \n",
505+
"\n",
507506
" \n",
508507
" x_start = x_start + grp_count\n",
508+
" \n",
509+
" ##################### DELTA PTS ON CONTRAST PLOT WIP \n",
510+
"\n",
511+
" contrast_show_deltas = plot_kwargs[\"contrast_show_deltas\"]\n",
512+
" \n",
513+
" if is_paired == None:\n",
514+
" contrast_show_deltas = False\n",
515+
" \n",
516+
" if contrast_show_deltas == True:\n",
517+
" \n",
518+
" trans = plt.gca().transData\n",
519+
" \n",
520+
" delta_plot_data_temp = plot_data.copy()\n",
521+
" delta_id_col = dabest_obj.id_col\n",
522+
" if color_col != None:\n",
523+
" delta_plot_data = delta_plot_data_temp[[xvar, yvar, delta_id_col, color_col]]\n",
524+
" deltapts_args = {\"hue\" : color_col, \n",
525+
" \"palette\" : plot_palette_raw,\n",
526+
" \"marker\" : \"^\",\n",
527+
" \"alpha\" : 0.5}\n",
528+
" \n",
529+
" else:\n",
530+
" delta_plot_data = delta_plot_data_temp[[xvar, yvar, delta_id_col]]\n",
531+
" deltapts_args = {\"color\" : \"k\",\n",
532+
" \"marker\" : \"^\",\n",
533+
" \"alpha\" : 0.5}\n",
534+
" \n",
535+
" final_deltas = pd.DataFrame()\n",
536+
" for i in idx:\n",
537+
" for j in i:\n",
538+
" if i.index(j) != 0:\n",
539+
" temp_df_exp = delta_plot_data[delta_plot_data[xvar].str.contains(j)].reset_index(drop=True)\n",
540+
" if is_paired == \"baseline\":\n",
541+
" temp_df_cont = delta_plot_data[delta_plot_data[xvar].str.contains(i[0])].reset_index(drop=True)\n",
542+
" elif is_paired == \"sequential\":\n",
543+
" temp_df_cont = delta_plot_data[delta_plot_data[xvar].str.contains(i[i.index(j) - 1])].reset_index(drop=True)\n",
544+
" delta_df = temp_df_exp.copy()\n",
545+
" delta_df[yvar] = temp_df_exp[yvar] - temp_df_cont[yvar]\n",
546+
" final_deltas = pd.concat([final_deltas, delta_df]) \n",
547+
" \n",
548+
" \n",
549+
" # Plot the raw data as a swarmplot.\n",
550+
" deltapts_plot = sns.swarmplot(data=final_deltas, x=xvar, y=yvar,\n",
551+
" ax=contrast_axes,\n",
552+
" order=all_plot_groups, \n",
553+
" zorder=2,\n",
554+
" **deltapts_args)\n",
555+
" contrast_axes.legend().set_visible(False)\n",
556+
" \n",
557+
" ##################### DELTA PTS ON CONTRAST PLOT END\n",
558+
"\n",
559+
" \n",
509560
" # Set the tick labels, because the slopegraph plotting doesn't.\n",
510561
" rawdata_axes.set_xticks(np.arange(0, len(temp_all_plot_groups)))\n",
511562
" rawdata_axes.set_xticklabels(temp_all_plot_groups)\n",
@@ -1343,7 +1394,10 @@
13431394
" contrast_axes.get_xaxis().set_visible(False)\n",
13441395
" \n",
13451396
" ####################################################### END GRIDKEY MAIN CODE WIP \n",
1346-
" \n",
1397+
" \n",
1398+
" \n",
1399+
" \n",
1400+
" \n",
13471401
" # Make sure no stray ticks appear!\n",
13481402
" rawdata_axes.xaxis.set_ticks_position('bottom')\n",
13491403
" rawdata_axes.yaxis.set_ticks_position('left')\n",
@@ -1358,6 +1412,14 @@
13581412
" # Return the figure.\n",
13591413
" return fig"
13601414
]
1415+
},
1416+
{
1417+
"cell_type": "code",
1418+
"execution_count": null,
1419+
"id": "7355251f",
1420+
"metadata": {},
1421+
"outputs": [],
1422+
"source": []
13611423
}
13621424
],
13631425
"metadata": {

0 commit comments

Comments
 (0)