Skip to content

Commit bc050ec

Browse files
committed
tutorial page completed + amendment
1 parent c034f61 commit bc050ec

18 files changed

Lines changed: 1135 additions & 344 deletions

dabest/_classes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2437,7 +2437,8 @@ def __pre_calc(self):
24372437
]
24382438
self.__results = out_.reindex(columns=columns_in_order)
24392439
self.__results.dropna(axis="columns", how="all", inplace=True)
2440-
2440+
if self.is_paired is None:
2441+
self.__results.insert(5, 'is_paired', self.__results.apply(lambda _: None, axis=1))
24412442
if self.__delta2 is True and self.__effect_size == "mean_diff":
24422443
self.__delta_delta = DeltaDelta(self,
24432444
self.__permutation_count,

dabest/plotter.py

Lines changed: 27 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -354,23 +354,11 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
354354
pivot_values = [yvar, color_col]
355355
pivoted_plot_data = pd.pivot(data=plot_data, index=dabest_obj.id_col,
356356
columns=xvar, values=pivot_values)
357-
if is_paired == "baseline":
358-
temp_idx = []
359-
for i in idx:
360-
control = i[0]
361-
temp_idx.extend(((control, test) for test in i[1:]))
362-
temp_idx = tuple(temp_idx)
363-
364-
temp_all_plot_groups = []
365-
for i in temp_idx:
366-
temp_all_plot_groups.extend(list(i))
367-
else:
368-
temp_idx = idx
369-
temp_all_plot_groups = all_plot_groups
370-
357+
371358
x_start = 0
372-
for ii, current_tuple in enumerate(temp_idx):
373-
if len(temp_idx) > 1:
359+
360+
for ii, current_tuple in enumerate(idx):
361+
if len(idx) > 1:
374362
# Select only the data for the current tuple.
375363
if color_col is None:
376364
current_pair = pivoted_plot_data.reindex(columns=current_tuple)
@@ -381,6 +369,7 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
381369
current_pair = pivoted_plot_data
382370
else:
383371
current_pair = pivoted_plot_data[yvar]
372+
384373
grp_count = len(current_tuple)
385374
# Iterate through the data for the current tuple.
386375
for ID, observation in current_pair.iterrows():
@@ -395,12 +384,13 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
395384
if not pd.isna(color_key):
396385
slopegraph_kwargs['color'] = plot_palette_raw[color_key]
397386
slopegraph_kwargs['label'] = color_key
398-
387+
399388
rawdata_axes.plot(x_points, y_points, **slopegraph_kwargs)
400389
x_start = x_start + grp_count
390+
401391
# Set the tick labels, because the slopegraph plotting doesn't.
402-
rawdata_axes.set_xticks(np.arange(0, len(temp_all_plot_groups)))
403-
rawdata_axes.set_xticklabels(temp_all_plot_groups)
392+
rawdata_axes.set_xticks(np.arange(0, len(all_plot_groups)))
393+
rawdata_axes.set_xticklabels(all_plot_groups)
404394

405395

406396
else:
@@ -467,18 +457,12 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
467457

468458
# Plot effect sizes and bootstraps.
469459
# Take note of where the `control` groups are.
470-
if is_paired == "baseline" and show_pairs == True:
471-
ticks_to_skip = np.arange(0, len(temp_all_plot_groups), 2).tolist()
472-
ticks_to_plot = np.arange(1, len(temp_all_plot_groups), 2).tolist()
473-
ticks_to_skip_contrast = np.cumsum([(len(t)-1)*2 for t in idx])[:-1].tolist()
474-
ticks_to_skip_contrast.insert(0, 0)
475-
else:
476-
ticks_to_skip = np.cumsum([len(t) for t in idx])[:-1].tolist()
477-
ticks_to_skip.insert(0, 0)
460+
ticks_to_skip = np.cumsum([len(t) for t in idx])[:-1].tolist()
461+
ticks_to_skip.insert(0, 0)
478462

479-
# Then obtain the ticks where we have to plot the effect sizes.
480-
ticks_to_plot = [t for t in range(0, len(all_plot_groups))
481-
if t not in ticks_to_skip]
463+
# Then obtain the ticks where we have to plot the effect sizes.
464+
ticks_to_plot = [t for t in range(0, len(all_plot_groups))
465+
if t not in ticks_to_skip]
482466

483467

484468
# Plot the bootstraps, then the effect sizes and CIs.
@@ -794,56 +778,22 @@ def EffectSizeDataFramePlotter(EffectSizeDataFrame, **plot_kwargs):
794778
if contrast_ylim_low < 0 < contrast_ylim_high:
795779
contrast_axes.axhline(y=0, **reflines_kwargs)
796780

797-
if is_paired == "baseline" and show_pairs == True:
798-
rightend_ticks_raw = np.array([len(i)-1 for i in temp_idx]) + np.array(ticks_to_skip)
799-
for ax in [rawdata_axes]:
800-
sns.despine(ax=ax, bottom=True)
801-
802-
ylim = ax.get_ylim()
803-
xlim = ax.get_xlim()
804-
redraw_axes_kwargs['y'] = ylim[0]
805-
806-
for k, start_tick in enumerate(ticks_to_skip):
807-
end_tick = rightend_ticks_raw[k]
808-
ax.hlines(xmin=start_tick, xmax=end_tick,
809-
**redraw_axes_kwargs)
810-
811-
ax.set_ylim(ylim)
812-
del redraw_axes_kwargs['y']
813-
814-
temp_length = [(len(i)-1)*2-1 for i in idx]
815-
rightend_ticks_contrast = np.array(temp_length) + np.array(ticks_to_skip_contrast)
816-
for ax in [contrast_axes]:
817-
sns.despine(ax=ax, bottom=True)
818-
819-
ylim = ax.get_ylim()
820-
xlim = ax.get_xlim()
821-
redraw_axes_kwargs['y'] = ylim[0]
822-
823-
for k, start_tick in enumerate(ticks_to_skip_contrast):
824-
end_tick = rightend_ticks_contrast[k]
825-
ax.hlines(xmin=start_tick, xmax=end_tick,
826-
**redraw_axes_kwargs)
827-
828-
ax.set_ylim(ylim)
829-
del redraw_axes_kwargs['y']
830-
else:
831-
# Compute the end of each x-axes line.
832-
rightend_ticks = np.array([len(i)-1 for i in idx]) + np.array(ticks_to_skip)
833-
for ax in [rawdata_axes, contrast_axes]:
834-
sns.despine(ax=ax, bottom=True)
781+
# Compute the end of each x-axes line.
782+
rightend_ticks = np.array([len(i)-1 for i in idx]) + np.array(ticks_to_skip)
783+
for ax in [rawdata_axes, contrast_axes]:
784+
sns.despine(ax=ax, bottom=True)
835785

836-
ylim = ax.get_ylim()
837-
xlim = ax.get_xlim()
838-
redraw_axes_kwargs['y'] = ylim[0]
786+
ylim = ax.get_ylim()
787+
xlim = ax.get_xlim()
788+
redraw_axes_kwargs['y'] = ylim[0]
839789

840-
for k, start_tick in enumerate(ticks_to_skip):
841-
end_tick = rightend_ticks[k]
842-
ax.hlines(xmin=start_tick, xmax=end_tick,
843-
**redraw_axes_kwargs)
790+
for k, start_tick in enumerate(ticks_to_skip):
791+
end_tick = rightend_ticks[k]
792+
ax.hlines(xmin=start_tick, xmax=end_tick,
793+
**redraw_axes_kwargs)
844794

845-
ax.set_ylim(ylim)
846-
del redraw_axes_kwargs['y']
795+
ax.set_ylim(ylim)
796+
del redraw_axes_kwargs['y']
847797

848798
if show_delta2 is True or show_mini_meta is True:
849799
ylim = contrast_axes.get_ylim()
43.5 KB
Loading
55 KB
Loading
50.7 KB
Loading
64.5 KB
Loading
70.2 KB
Loading
93.4 KB
Loading
38 KB
Loading
37.7 KB
Loading

0 commit comments

Comments
 (0)