Skip to content

Commit e6268a9

Browse files
committed
Update test_03_plotting.py
1 parent 9193578 commit e6268a9

1 file changed

Lines changed: 81 additions & 82 deletions

File tree

dabest/tests/test_03_plotting.py

Lines changed: 81 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424

2525
two_groups_unpaired = load(df, idx=("Control 1", "Test 1"))
2626

27-
two_groups_paired = load(df, idx=("Control 1", "Test 1"),
27+
two_groups_paired = load(df, idx=("Control 1", "Test 1"),
2828
paired=True, id_col="ID")
29-
29+
3030
multi_2group = load(df, idx=(("Control 1", "Test 1",),
3131
("Control 2", "Test 2"))
3232
)
33-
34-
multi_2group_paired = load(df,
33+
34+
multi_2group_paired = load(df,
3535
idx=(("Control 1", "Test 1"),
3636
("Control 2", "Test 2")),
3737
paired=True, id_col="ID")
@@ -40,7 +40,7 @@
4040
"Test 2", "Test 3",
4141
"Test 4", "Test 5", "Test 6")
4242
)
43-
43+
4444
multi_groups = load(df, idx=(("Control 1", "Test 1",),
4545
("Control 2", "Test 2","Test 3"),
4646
("Control 3", "Test 4","Test 5", "Test 6")
@@ -49,101 +49,101 @@
4949

5050

5151

52-
@pytest.mark.mpl_image_compare
52+
@pytest.mark.mpl_image_compare(tolerance=10)
5353
def test_01_gardner_altman_unpaired_meandiff():
5454
return two_groups_unpaired.mean_diff.plot();
5555

5656

5757

58-
@pytest.mark.mpl_image_compare
58+
@pytest.mark.mpl_image_compare(tolerance=10)
5959
def test_02_gardner_altman_unpaired_mediandiff():
6060
return two_groups_unpaired.median_diff.plot();
6161

6262

6363

64-
@pytest.mark.mpl_image_compare
64+
@pytest.mark.mpl_image_compare(tolerance=10)
6565
def test_03_gardner_altman_unpaired_hedges_g():
6666
return two_groups_unpaired.hedges_g.plot();
6767

6868

6969

70-
@pytest.mark.mpl_image_compare
70+
@pytest.mark.mpl_image_compare(tolerance=10)
7171
def test_04_gardner_altman_paired_meandiff():
7272
return two_groups_paired.mean_diff.plot();
7373

7474

7575

76-
@pytest.mark.mpl_image_compare
76+
@pytest.mark.mpl_image_compare(tolerance=10)
7777
def test_04_gardner_altman_paired_hedges_g():
7878
return two_groups_paired.hedges_g.plot();
7979

8080

81-
82-
@pytest.mark.mpl_image_compare
81+
82+
@pytest.mark.mpl_image_compare(tolerance=10)
8383
def test_05_cummings_two_group_unpaired_meandiff():
8484
return two_groups_unpaired.mean_diff.plot(fig_size=(4, 6),
8585
float_contrast=False);
8686

8787

8888

89-
@pytest.mark.mpl_image_compare
89+
@pytest.mark.mpl_image_compare(tolerance=10)
9090
def test_06_cummings_two_group_paired_meandiff():
9191
return two_groups_paired.mean_diff.plot(fig_size=(6, 6),
9292
float_contrast=False);
9393

9494

9595

96-
@pytest.mark.mpl_image_compare
96+
@pytest.mark.mpl_image_compare(tolerance=10)
9797
def test_07_cummings_multi_group_unpaired():
9898
return multi_2group.mean_diff.plot();
9999

100100

101101

102-
@pytest.mark.mpl_image_compare
102+
@pytest.mark.mpl_image_compare(tolerance=10)
103103
def test_08_cummings_multi_group_paired():
104104
return multi_2group_paired.mean_diff.plot(fig_size=(6, 6));
105105

106106

107107

108-
@pytest.mark.mpl_image_compare
108+
@pytest.mark.mpl_image_compare(tolerance=10)
109109
def test_09_cummings_shared_control():
110110
return shared_control.mean_diff.plot();
111111

112112

113113

114-
@pytest.mark.mpl_image_compare
114+
@pytest.mark.mpl_image_compare(tolerance=10)
115115
def test_10_cummings_multi_groups():
116116
return multi_groups.mean_diff.plot();
117117

118118

119119

120-
@pytest.mark.mpl_image_compare(tolerance=20)
120+
@pytest.mark.mpl_image_compare(tolerance=10)
121121
def test_11_inset_plots():
122-
122+
123123
# Load the iris dataset. Requires internet access.
124124
iris = pd.read_csv("https://github.com/mwaskom/seaborn-data/raw/master/iris.csv")
125-
iris_melt = pd.melt(iris.reset_index(),
125+
iris_melt = pd.melt(iris.reset_index(),
126126
id_vars=["species", "index"], var_name="metric")
127-
128-
129-
127+
128+
129+
130130
# Load the above data into `dabest`.
131131
iris_dabest1 = load(data=iris, x="species", y="petal_width",
132132
idx=("setosa", "versicolor", "virginica"))
133133

134134
iris_dabest2 = load(data=iris, x="species", y="sepal_width",
135135
idx=("setosa", "versicolor"))
136136

137-
iris_dabest3 = load(data=iris_melt[iris_melt.species=="setosa"],
137+
iris_dabest3 = load(data=iris_melt[iris_melt.species=="setosa"],
138138
x="metric", y="value",
139139
idx=("sepal_length", "sepal_width"),
140140
paired=True, id_col="index")
141-
142-
143-
141+
142+
143+
144144
# Create Figure.
145-
fig, ax = plt.subplots(nrows=2, ncols=2,
146-
figsize=(15, 15),
145+
fig, ax = plt.subplots(nrows=2, ncols=2,
146+
figsize=(15, 15),
147147
gridspec_kw={"wspace":0.5})
148148

149149
iris_dabest1.mean_diff.plot(ax=ax.flat[0]);
@@ -153,87 +153,87 @@ def test_11_inset_plots():
153153
iris_dabest3.mean_diff.plot(ax=ax.flat[2]);
154154

155155
iris_dabest3.mean_diff.plot(ax=ax.flat[3], float_contrast=False);
156-
156+
157157
return fig
158-
159-
160-
161-
@pytest.mark.mpl_image_compare
158+
159+
160+
161+
@pytest.mark.mpl_image_compare(tolerance=10)
162162
def test_12_gardner_altman_ylabel():
163-
return two_groups_unpaired.mean_diff.plot(swarm_label="This is my\nrawdata",
163+
return two_groups_unpaired.mean_diff.plot(swarm_label="This is my\nrawdata",
164164
contrast_label="The bootstrap\ndistribtions!");
165-
166165

167166

168-
@pytest.mark.mpl_image_compare
167+
168+
@pytest.mark.mpl_image_compare(tolerance=10)
169169
def test_13_multi_2group_color():
170170
return multi_2group.mean_diff.plot(color_col="Gender");
171171

172172

173173

174-
@pytest.mark.mpl_image_compare
174+
@pytest.mark.mpl_image_compare(tolerance=10)
175175
def test_14_gardner_altman_paired_color():
176176
return two_groups_paired.mean_diff.plot(fig_size=(6, 6),
177177
color_col="Gender");
178178

179179

180180

181-
@pytest.mark.mpl_image_compare
181+
@pytest.mark.mpl_image_compare(tolerance=10)
182182
def test_15_change_palette_a():
183183
return multi_2group.mean_diff.plot(fig_size=(8, 6),
184-
color_col="Gender",
184+
color_col="Gender",
185185
custom_palette="Dark2");
186186

187187

188188

189-
@pytest.mark.mpl_image_compare
189+
@pytest.mark.mpl_image_compare(tolerance=10)
190190
def test_16_change_palette_b():
191191
return multi_2group.mean_diff.plot(custom_palette="Paired");
192192

193193

194194

195-
my_color_palette = {"Control 1" : "blue",
195+
my_color_palette = {"Control 1" : "blue",
196196
"Test 1" : "purple",
197197
"Control 2" : "#cb4b16", # This is a hex string.
198198
"Test 2" : (0., 0.7, 0.2) # This is a RGB tuple.
199199
}
200-
201-
@pytest.mark.mpl_image_compare
200+
201+
@pytest.mark.mpl_image_compare(tolerance=10)
202202
def test_17_change_palette_c():
203203
return multi_2group.mean_diff.plot(custom_palette=my_color_palette);
204204

205205

206206

207-
@pytest.mark.mpl_image_compare
207+
@pytest.mark.mpl_image_compare(tolerance=10)
208208
def test_18_desat():
209-
return multi_2group.mean_diff.plot(custom_palette=my_color_palette,
210-
swarm_desat=0.75,
209+
return multi_2group.mean_diff.plot(custom_palette=my_color_palette,
210+
swarm_desat=0.75,
211211
halfviolin_desat=0.25);
212212

213213

214214

215-
@pytest.mark.mpl_image_compare
215+
@pytest.mark.mpl_image_compare(tolerance=10)
216216
def test_19_dot_sizes():
217-
return multi_2group.mean_diff.plot(raw_marker_size=3,
217+
return multi_2group.mean_diff.plot(raw_marker_size=3,
218218
es_marker_size=12);
219219

220220

221221

222-
@pytest.mark.mpl_image_compare
222+
@pytest.mark.mpl_image_compare(tolerance=10)
223223
def test_20_change_ylims():
224-
return multi_2group.mean_diff.plot(swarm_ylim=(0, 5),
224+
return multi_2group.mean_diff.plot(swarm_ylim=(0, 5),
225225
contrast_ylim=(-2, 2));
226226

227227

228228

229-
@pytest.mark.mpl_image_compare
229+
@pytest.mark.mpl_image_compare(tolerance=10)
230230
def test_21_invert_ylim():
231-
return multi_2group.mean_diff.plot(contrast_ylim=(2, -2),
231+
return multi_2group.mean_diff.plot(contrast_ylim=(2, -2),
232232
contrast_label="More negative is better!");
233233

234234

235235

236-
@pytest.mark.mpl_image_compare
236+
@pytest.mark.mpl_image_compare(tolerance=10)
237237
def test_22_ticker_gardner_altman():
238238

239239
f = two_groups_unpaired.mean_diff.plot()
@@ -246,12 +246,12 @@ def test_22_ticker_gardner_altman():
246246

247247
contrast_axes.yaxis.set_major_locator(Ticker.MultipleLocator(0.5))
248248
contrast_axes.yaxis.set_minor_locator(Ticker.MultipleLocator(0.25))
249-
249+
250250
return f
251251

252252

253253

254-
@pytest.mark.mpl_image_compare
254+
@pytest.mark.mpl_image_compare(tolerance=10)
255255
def test_23_ticker_cumming():
256256
f = multi_2group.mean_diff.plot(swarm_ylim=(0,6),
257257
contrast_ylim=(-3, 1))
@@ -264,7 +264,7 @@ def test_23_ticker_cumming():
264264

265265
contrast_axes.yaxis.set_major_locator(Ticker.MultipleLocator(0.5))
266266
contrast_axes.yaxis.set_minor_locator(Ticker.MultipleLocator(0.25))
267-
267+
268268
return f
269269

270270

@@ -278,83 +278,82 @@ def test_23_ticker_cumming():
278278
wide_df = pd.concat([c1, t1, t2, t3],axis=1)
279279

280280

281-
long_df = pd.melt(wide_df,
281+
long_df = pd.melt(wide_df,
282282
value_vars=["Control", "Test 1", "Test 2", "Test 3"],
283283
value_name="value",
284284
var_name="group")
285285
long_df['dummy'] = np.repeat(np.nan, len(long_df))
286286

287287

288288

289-
@pytest.mark.mpl_image_compare
289+
@pytest.mark.mpl_image_compare(tolerance=10)
290290
def test_24_wide_df_nan():
291291

292-
wide_df_dabest = load(wide_df,
292+
wide_df_dabest = load(wide_df,
293293
idx=("Control", "Test 1", "Test 2", "Test 3")
294294
)
295295

296-
return wide_df_dabest.mean_diff.plot();
296+
return wide_df_dabest.mean_diff.plot();
297297

298298

299299

300-
@pytest.mark.mpl_image_compare
300+
@pytest.mark.mpl_image_compare(tolerance=10)
301301
def test_25_long_df_nan():
302302

303303
long_df_dabest = load(long_df, x="group", y="value",
304304
idx=("Control", "Test 1", "Test 2", "Test 3")
305305
)
306306

307-
return long_df_dabest.mean_diff.plot();
308-
309-
310-
311-
@pytest.mark.mpl_image_compare
307+
return long_df_dabest.mean_diff.plot();
308+
309+
310+
311+
@pytest.mark.mpl_image_compare(tolerance=10)
312312
def test_26_slopegraph_kwargs():
313-
313+
314314
return two_groups_paired.mean_diff.plot(
315315
slopegraph_kwargs=dict(linestyle='dotted')
316316
);
317-
318317

319318

320-
@pytest.mark.mpl_image_compare
319+
320+
@pytest.mark.mpl_image_compare(tolerance=10)
321321
def test_27_gardner_altman_reflines_kwargs():
322-
322+
323323
return two_groups_unpaired.mean_diff.plot(
324324
reflines_kwargs=dict(linestyle='dotted')
325325
);
326326

327327

328328

329-
@pytest.mark.mpl_image_compare
329+
@pytest.mark.mpl_image_compare(tolerance=10)
330330
def test_28_unpaired_cumming_reflines_kwargs():
331-
331+
332332
return two_groups_unpaired.mean_diff.plot(
333333
fig_size=(12,10),
334334
float_contrast=False,
335-
reflines_kwargs=dict(linestyle='dotted',
335+
reflines_kwargs=dict(linestyle='dotted',
336336
linewidth=2),
337337
contrast_ylim=(-1, 1)
338338
);
339339

340340

341341

342-
@pytest.mark.mpl_image_compare
342+
@pytest.mark.mpl_image_compare(tolerance=10)
343343
def test_28_paired_cumming_slopegraph_reflines_kwargs():
344-
344+
345345
return two_groups_paired.mean_diff.plot(float_contrast=False,
346346
color_col="Gender",
347347
slopegraph_kwargs=dict(linestyle='dotted'),
348-
reflines_kwargs=dict(linestyle='dashed',
348+
reflines_kwargs=dict(linestyle='dashed',
349349
linewidth=2),
350350
contrast_ylim=(-1, 1)
351351
);
352-
353-
354-
@pytest.mark.mpl_image_compare
352+
353+
354+
@pytest.mark.mpl_image_compare(tolerance=10)
355355
def test_99_style_sheets():
356356
# Perform this test last so we don't have to reset the plot style.
357357
plt.style.use("dark_background")
358-
358+
359359
return multi_2group.mean_diff.plot();
360-

0 commit comments

Comments
 (0)