@@ -44,13 +44,60 @@ def test_unequal_data_label_length(self):
44
44
self .assertRaises (PlotlyError , tls .FigureFactory .create_distplot ,
45
45
** kwargs )
46
46
47
- def test_simple_distplot (self ):
47
+ def test_simple_distplot_prob_density (self ):
48
48
49
49
# we should be able to create a single distplot with a simple dataset
50
50
# and default kwargs
51
51
52
52
dp = tls .FigureFactory .create_distplot (hist_data = [[1 , 2 , 2 , 3 ]],
53
- group_labels = ['distplot' ])
53
+ group_labels = ['distplot' ],
54
+ histnorm = 'probability density' )
55
+ expected_dp_layout = {'barmode' : 'overlay' ,
56
+ 'hovermode' : 'closest' ,
57
+ 'legend' : {'traceorder' : 'reversed' },
58
+ 'xaxis1' : {'anchor' : 'y2' , 'domain' : [0.0 , 1.0 ], 'zeroline' : False },
59
+ 'yaxis1' : {'anchor' : 'free' , 'domain' : [0.35 , 1 ], 'position' : 0.0 },
60
+ 'yaxis2' : {'anchor' : 'x1' ,
61
+ 'domain' : [0 , 0.25 ],
62
+ 'dtick' : 1 ,
63
+ 'showticklabels' : False }}
64
+ self .assertEqual (dp ['layout' ], expected_dp_layout )
65
+
66
+ expected_dp_data_hist = {'autobinx' : False ,
67
+ 'histnorm' : 'probability density' ,
68
+ 'legendgroup' : 'distplot' ,
69
+ 'marker' : {'color' : 'rgb(31, 119, 180)' },
70
+ 'name' : 'distplot' ,
71
+ 'opacity' : 0.7 ,
72
+ 'type' : 'histogram' ,
73
+ 'x' : [1 , 2 , 2 , 3 ],
74
+ 'xaxis' : 'x1' ,
75
+ 'xbins' : {'end' : 3.0 , 'size' : 1.0 , 'start' : 1.0 },
76
+ 'yaxis' : 'y1' }
77
+ self .assertEqual (dp ['data' ][0 ], expected_dp_data_hist )
78
+
79
+ expected_dp_data_rug = {'legendgroup' : 'distplot' ,
80
+ 'marker' : {'color' : 'rgb(31, 119, 180)' ,
81
+ 'symbol' : 'line-ns-open' },
82
+ 'mode' : 'markers' ,
83
+ 'name' : 'distplot' ,
84
+ 'showlegend' : False ,
85
+ 'text' : None ,
86
+ 'type' : 'scatter' ,
87
+ 'x' : [1 , 2 , 2 , 3 ],
88
+ 'xaxis' : 'x1' ,
89
+ 'y' : ['distplot' , 'distplot' ,
90
+ 'distplot' , 'distplot' ],
91
+ 'yaxis' : 'y2' }
92
+ self .assertEqual (dp ['data' ][2 ], expected_dp_data_rug )
93
+
94
+ def test_simple_distplot_prob (self ):
95
+
96
+ # we should be able to create a single distplot with a simple dataset
97
+ # and default kwargs
98
+
99
+ dp = tls .FigureFactory .create_distplot (hist_data = [[1 , 2 , 2 , 3 ]],
100
+ group_labels = ['distplot' ], histnorm = 'probability' )
54
101
expected_dp_layout = {'barmode' : 'overlay' ,
55
102
'hovermode' : 'closest' ,
56
103
'legend' : {'traceorder' : 'reversed' },
@@ -90,7 +137,7 @@ def test_simple_distplot(self):
90
137
'yaxis' : 'y2' }
91
138
self .assertEqual (dp ['data' ][2 ], expected_dp_data_rug )
92
139
93
- def test_distplot_more_args (self ):
140
+ def test_distplot_more_args_prob_dens (self ):
94
141
95
142
# we should be able to create a distplot with 2 datasets no
96
143
# rugplot, defined bin_size, and added title
@@ -106,6 +153,69 @@ def test_distplot_more_args(self):
106
153
group_labels = ['2012' , '2013' ]
107
154
108
155
dp = tls .FigureFactory .create_distplot (hist_data , group_labels ,
156
+ histnorm = 'probability density' ,
157
+ show_rug = False , bin_size = .2 )
158
+ dp ['layout' ].update (title = 'Dist Plot' )
159
+
160
+ expected_dp_layout = {'barmode' : 'overlay' ,
161
+ 'hovermode' : 'closest' ,
162
+ 'legend' : {'traceorder' : 'reversed' },
163
+ 'title' : 'Dist Plot' ,
164
+ 'xaxis1' : {'anchor' : 'y2' , 'domain' : [0.0 , 1.0 ],
165
+ 'zeroline' : False },
166
+ 'yaxis1' : {'anchor' : 'free' , 'domain' : [0.0 , 1 ],
167
+ 'position' : 0.0 }}
168
+ self .assertEqual (dp ['layout' ], expected_dp_layout )
169
+
170
+ expected_dp_data_hist_1 = {'autobinx' : False ,
171
+ 'histnorm' : 'probability density' ,
172
+ 'legendgroup' : '2012' ,
173
+ 'marker' : {'color' : 'rgb(31, 119, 180)' },
174
+ 'name' : '2012' ,
175
+ 'opacity' : 0.7 ,
176
+ 'type' : 'histogram' ,
177
+ 'x' : [0.8 , 1.2 , 0.2 , 0.6 , 1.6 , - 0.9 , - 0.07 ,
178
+ 1.95 , 0.9 , - 0.2 , - 0.5 , 0.3 , 0.4 ,
179
+ - 0.37 , 0.6 ],
180
+ 'xaxis' : 'x1' ,
181
+ 'xbins' : {'end' : 1.95 , 'size' : 0.2 ,
182
+ 'start' : - 0.9 },
183
+ 'yaxis' : 'y1' }
184
+ self .assertEqual (dp ['data' ][0 ], expected_dp_data_hist_1 )
185
+
186
+ expected_dp_data_hist_2 = {'autobinx' : False ,
187
+ 'histnorm' : 'probability density' ,
188
+ 'legendgroup' : '2013' ,
189
+ 'marker' : {'color' : 'rgb(255, 127, 14)' },
190
+ 'name' : '2013' ,
191
+ 'opacity' : 0.7 ,
192
+ 'type' : 'histogram' ,
193
+ 'x' : [0.8 , 1.5 , 1.5 , 0.6 , 0.59 , 1.0 , 0.8 ,
194
+ 1.7 , 0.5 , 0.8 , - 0.3 , 1.2 , 0.56 , 0.3 ,
195
+ 2.2 ],
196
+ 'xaxis' : 'x1' ,
197
+ 'xbins' : {'end' : 2.2 , 'size' : 0.2 ,
198
+ 'start' : - 0.3 },
199
+ 'yaxis' : 'y1' }
200
+ self .assertEqual (dp ['data' ][1 ], expected_dp_data_hist_2 )
201
+
202
+ def test_distplot_more_args_prob (self ):
203
+
204
+ # we should be able to create a distplot with 2 datasets no
205
+ # rugplot, defined bin_size, and added title
206
+
207
+ hist1_x = [0.8 , 1.2 , 0.2 , 0.6 , 1.6 ,
208
+ - 0.9 , - 0.07 , 1.95 , 0.9 , - 0.2 ,
209
+ - 0.5 , 0.3 , 0.4 , - 0.37 , 0.6 ]
210
+ hist2_x = [0.8 , 1.5 , 1.5 , 0.6 , 0.59 ,
211
+ 1.0 , 0.8 , 1.7 , 0.5 , 0.8 ,
212
+ - 0.3 , 1.2 , 0.56 , 0.3 , 2.2 ]
213
+
214
+ hist_data = [hist1_x ] + [hist2_x ]
215
+ group_labels = ['2012' , '2013' ]
216
+
217
+ dp = tls .FigureFactory .create_distplot (hist_data , group_labels ,
218
+ histnorm = 'probability' ,
109
219
show_rug = False , bin_size = .2 )
110
220
dp ['layout' ].update (title = 'Dist Plot' )
111
221
@@ -151,7 +261,55 @@ def test_distplot_more_args(self):
151
261
'yaxis' : 'y1' }
152
262
self .assertEqual (dp ['data' ][1 ], expected_dp_data_hist_2 )
153
263
154
- def test_distplot_binsize_array (self ):
264
+ def test_distplot_binsize_array_prob (self ):
265
+ hist1_x = [0.8 , 1.2 , 0.2 , 0.6 , 1.6 , - 0.9 , - 0.07 , 1.95 , 0.9 , - 0.2 ,
266
+ - 0.5 , 0.3 , 0.4 , - 0.37 , 0.6 ]
267
+ hist2_x = [0.8 , 1.5 , 1.5 , 0.6 , 0.59 , 1.0 , 0.8 , 1.7 , 0.5 , 0.8 , - 0.3 ,
268
+ 1.2 , 0.56 , 0.3 , 2.2 ]
269
+
270
+ hist_data = [hist1_x , hist2_x ]
271
+ group_labels = ['2012' , '2013' ]
272
+
273
+ dp = tls .FigureFactory .create_distplot (hist_data , group_labels ,
274
+ histnorm = 'probability' ,
275
+ show_rug = False ,
276
+ bin_size = [.2 , .2 ])
277
+
278
+ expected_dp_data_hist_1 = {'autobinx' : False ,
279
+ 'histnorm' : 'probability density' ,
280
+ 'legendgroup' : '2012' ,
281
+ 'marker' :
282
+ {'color' : 'rgb(31, 119, 180)' },
283
+ 'name' : '2012' ,
284
+ 'opacity' : 0.7 ,
285
+ 'type' : 'histogram' ,
286
+ 'x' : [0.8 , 1.2 , 0.2 , 0.6 , 1.6 , - 0.9 ,
287
+ - 0.07 , 1.95 , 0.9 , - 0.2 , - 0.5 , 0.3 ,
288
+ 0.4 , - 0.37 , 0.6 ],
289
+ 'xaxis' : 'x1' ,
290
+ 'xbins' : {'end' : 1.95 , 'size' : 0.2 ,
291
+ 'start' : - 0.9 },
292
+ 'yaxis' : 'y1' }
293
+ self .assertEqual (dp ['data' ][0 ], expected_dp_data_hist_1 )
294
+
295
+ expected_dp_data_hist_2 = {'autobinx' : False ,
296
+ 'histnorm' : 'probability density' ,
297
+ 'legendgroup' : '2013' ,
298
+ 'marker' :
299
+ {'color' : 'rgb(255, 127, 14)' },
300
+ 'name' : '2013' ,
301
+ 'opacity' : 0.7 ,
302
+ 'type' : 'histogram' ,
303
+ 'x' : [0.8 , 1.5 , 1.5 , 0.6 , 0.59 , 1.0 ,
304
+ 0.8 , 1.7 , 0.5 , 0.8 , - 0.3 , 1.2 ,
305
+ 0.56 , 0.3 , 2.2 ],
306
+ 'xaxis' : 'x1' ,
307
+ 'xbins' : {'end' : 2.2 , 'size' : 0.2 ,
308
+ 'start' : - 0.3 },
309
+ 'yaxis' : 'y1' }
310
+ self .assertEqual (dp ['data' ][1 ], expected_dp_data_hist_2 )
311
+
312
+ def test_distplot_binsize_array_prob_density (self ):
155
313
hist1_x = [0.8 , 1.2 , 0.2 , 0.6 , 1.6 , - 0.9 , - 0.07 , 1.95 , 0.9 , - 0.2 ,
156
314
- 0.5 , 0.3 , 0.4 , - 0.37 , 0.6 ]
157
315
hist2_x = [0.8 , 1.5 , 1.5 , 0.6 , 0.59 , 1.0 , 0.8 , 1.7 , 0.5 , 0.8 , - 0.3 ,
@@ -161,35 +319,38 @@ def test_distplot_binsize_array(self):
161
319
group_labels = ['2012' , '2013' ]
162
320
163
321
dp = tls .FigureFactory .create_distplot (hist_data , group_labels ,
322
+ histnorm = 'probability' ,
164
323
show_rug = False ,
165
324
bin_size = [.2 , .2 ])
166
325
167
326
expected_dp_data_hist_1 = {'autobinx' : False ,
168
- 'histnorm' : 'probability' ,
327
+ 'histnorm' : 'probability density ' ,
169
328
'legendgroup' : '2012' ,
170
- 'marker' : {'color' : 'rgb(31, 119, 180)' },
329
+ 'marker' :
330
+ {'color' : 'rgb(31, 119, 180)' },
171
331
'name' : '2012' ,
172
332
'opacity' : 0.7 ,
173
333
'type' : 'histogram' ,
174
- 'x' : [0.8 , 1.2 , 0.2 , 0.6 , 1.6 , - 0.9 , - 0.07 ,
175
- 1.95 , 0.9 , - 0.2 , - 0.5 , 0.3 , 0.4 ,
176
- - 0.37 , 0.6 ],
334
+ 'x' : [0.8 , 1.2 , 0.2 , 0.6 , 1.6 , - 0.9 ,
335
+ - 0.07 , 1.95 , 0.9 , - 0.2 , - 0.5 , 0.3 ,
336
+ 0.4 , - 0.37 , 0.6 ],
177
337
'xaxis' : 'x1' ,
178
338
'xbins' : {'end' : 1.95 , 'size' : 0.2 ,
179
339
'start' : - 0.9 },
180
340
'yaxis' : 'y1' }
181
341
self .assertEqual (dp ['data' ][0 ], expected_dp_data_hist_1 )
182
342
183
343
expected_dp_data_hist_2 = {'autobinx' : False ,
184
- 'histnorm' : 'probability' ,
344
+ 'histnorm' : 'probability density ' ,
185
345
'legendgroup' : '2013' ,
186
- 'marker' : {'color' : 'rgb(255, 127, 14)' },
346
+ 'marker' :
347
+ {'color' : 'rgb(255, 127, 14)' },
187
348
'name' : '2013' ,
188
349
'opacity' : 0.7 ,
189
350
'type' : 'histogram' ,
190
- 'x' : [0.8 , 1.5 , 1.5 , 0.6 , 0.59 , 1.0 , 0.8 ,
191
- 1.7 , 0.5 , 0.8 , - 0.3 , 1.2 , 0.56 , 0.3 ,
192
- 2.2 ],
351
+ 'x' : [0.8 , 1.5 , 1.5 , 0.6 , 0.59 , 1.0 ,
352
+ 0.8 , 1.7 , 0.5 , 0.8 , - 0.3 , 1.2 ,
353
+ 0.56 , 0.3 , 2.2 ],
193
354
'xaxis' : 'x1' ,
194
355
'xbins' : {'end' : 2.2 , 'size' : 0.2 ,
195
356
'start' : - 0.3 },
0 commit comments