@@ -44,13 +44,14 @@ 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' )
54
55
expected_dp_layout = {'barmode' : 'overlay' ,
55
56
'hovermode' : 'closest' ,
56
57
'legend' : {'traceorder' : 'reversed' },
@@ -90,7 +91,53 @@ def test_simple_distplot(self):
90
91
'yaxis' : 'y2' }
91
92
self .assertEqual (dp ['data' ][2 ], expected_dp_data_rug )
92
93
93
- def test_distplot_more_args (self ):
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' )
101
+ expected_dp_layout = {'barmode' : 'overlay' ,
102
+ 'hovermode' : 'closest' ,
103
+ 'legend' : {'traceorder' : 'reversed' },
104
+ 'xaxis1' : {'anchor' : 'y2' , 'domain' : [0.0 , 1.0 ], 'zeroline' : False },
105
+ 'yaxis1' : {'anchor' : 'free' , 'domain' : [0.35 , 1 ], 'position' : 0.0 },
106
+ 'yaxis2' : {'anchor' : 'x1' ,
107
+ 'domain' : [0 , 0.25 ],
108
+ 'dtick' : 1 ,
109
+ 'showticklabels' : False }}
110
+ self .assertEqual (dp ['layout' ], expected_dp_layout )
111
+
112
+ expected_dp_data_hist = {'autobinx' : False ,
113
+ 'histnorm' : 'probability' ,
114
+ 'legendgroup' : 'distplot' ,
115
+ 'marker' : {'color' : 'rgb(31, 119, 180)' },
116
+ 'name' : 'distplot' ,
117
+ 'opacity' : 0.7 ,
118
+ 'type' : 'histogram' ,
119
+ 'x' : [1 , 2 , 2 , 3 ],
120
+ 'xaxis' : 'x1' ,
121
+ 'xbins' : {'end' : 3.0 , 'size' : 1.0 , 'start' : 1.0 },
122
+ 'yaxis' : 'y1' }
123
+ self .assertEqual (dp ['data' ][0 ], expected_dp_data_hist )
124
+
125
+ expected_dp_data_rug = {'legendgroup' : 'distplot' ,
126
+ 'marker' : {'color' : 'rgb(31, 119, 180)' ,
127
+ 'symbol' : 'line-ns-open' },
128
+ 'mode' : 'markers' ,
129
+ 'name' : 'distplot' ,
130
+ 'showlegend' : False ,
131
+ 'text' : None ,
132
+ 'type' : 'scatter' ,
133
+ 'x' : [1 , 2 , 2 , 3 ],
134
+ 'xaxis' : 'x1' ,
135
+ 'y' : ['distplot' , 'distplot' ,
136
+ 'distplot' , 'distplot' ],
137
+ 'yaxis' : 'y2' }
138
+ self .assertEqual (dp ['data' ][2 ], expected_dp_data_rug )
139
+
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,7 @@ 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' ,
109
157
show_rug = False , bin_size = .2 )
110
158
dp ['layout' ].update (title = 'Dist Plot' )
111
159
@@ -151,7 +199,115 @@ def test_distplot_more_args(self):
151
199
'yaxis' : 'y1' }
152
200
self .assertEqual (dp ['data' ][1 ], expected_dp_data_hist_2 )
153
201
154
- def test_distplot_binsize_array (self ):
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
+ show_rug = False , bin_size = .2 )
219
+ dp ['layout' ].update (title = 'Dist Plot' )
220
+
221
+ expected_dp_layout = {'barmode' : 'overlay' ,
222
+ 'hovermode' : 'closest' ,
223
+ 'legend' : {'traceorder' : 'reversed' },
224
+ 'title' : 'Dist Plot' ,
225
+ 'xaxis1' : {'anchor' : 'y2' , 'domain' : [0.0 , 1.0 ],
226
+ 'zeroline' : False },
227
+ 'yaxis1' : {'anchor' : 'free' , 'domain' : [0.0 , 1 ],
228
+ 'position' : 0.0 }}
229
+ self .assertEqual (dp ['layout' ], expected_dp_layout )
230
+
231
+ expected_dp_data_hist_1 = {'autobinx' : False ,
232
+ 'histnorm' : 'probability' ,
233
+ 'legendgroup' : '2012' ,
234
+ 'marker' : {'color' : 'rgb(31, 119, 180)' },
235
+ 'name' : '2012' ,
236
+ 'opacity' : 0.7 ,
237
+ 'type' : 'histogram' ,
238
+ 'x' : [0.8 , 1.2 , 0.2 , 0.6 , 1.6 , - 0.9 , - 0.07 ,
239
+ 1.95 , 0.9 , - 0.2 , - 0.5 , 0.3 , 0.4 ,
240
+ - 0.37 , 0.6 ],
241
+ 'xaxis' : 'x1' ,
242
+ 'xbins' : {'end' : 1.95 , 'size' : 0.2 ,
243
+ 'start' : - 0.9 },
244
+ 'yaxis' : 'y1' }
245
+ self .assertEqual (dp ['data' ][0 ], expected_dp_data_hist_1 )
246
+
247
+ expected_dp_data_hist_2 = {'autobinx' : False ,
248
+ 'histnorm' : 'probability' ,
249
+ 'legendgroup' : '2013' ,
250
+ 'marker' : {'color' : 'rgb(255, 127, 14)' },
251
+ 'name' : '2013' ,
252
+ 'opacity' : 0.7 ,
253
+ 'type' : 'histogram' ,
254
+ 'x' : [0.8 , 1.5 , 1.5 , 0.6 , 0.59 , 1.0 , 0.8 ,
255
+ 1.7 , 0.5 , 0.8 , - 0.3 , 1.2 , 0.56 , 0.3 ,
256
+ 2.2 ],
257
+ 'xaxis' : 'x1' ,
258
+ 'xbins' : {'end' : 2.2 , 'size' : 0.2 ,
259
+ 'start' : - 0.3 },
260
+ 'yaxis' : 'y1' }
261
+ self .assertEqual (dp ['data' ][1 ], expected_dp_data_hist_2 )
262
+
263
+ def test_distplot_binsize_array_prob (self ):
264
+ hist1_x = [0.8 , 1.2 , 0.2 , 0.6 , 1.6 , - 0.9 , - 0.07 , 1.95 , 0.9 , - 0.2 ,
265
+ - 0.5 , 0.3 , 0.4 , - 0.37 , 0.6 ]
266
+ hist2_x = [0.8 , 1.5 , 1.5 , 0.6 , 0.59 , 1.0 , 0.8 , 1.7 , 0.5 , 0.8 , - 0.3 ,
267
+ 1.2 , 0.56 , 0.3 , 2.2 ]
268
+
269
+ hist_data = [hist1_x , hist2_x ]
270
+ group_labels = ['2012' , '2013' ]
271
+
272
+ dp = tls .FigureFactory .create_distplot (hist_data , group_labels ,
273
+ show_rug = False ,
274
+ bin_size = [.2 , .2 ])
275
+
276
+ expected_dp_data_hist_1 = {'autobinx' : False ,
277
+ 'histnorm' : 'probability density' ,
278
+ 'legendgroup' : '2012' ,
279
+ 'marker' :
280
+ {'color' : 'rgb(31, 119, 180)' },
281
+ 'name' : '2012' ,
282
+ 'opacity' : 0.7 ,
283
+ 'type' : 'histogram' ,
284
+ 'x' : [0.8 , 1.2 , 0.2 , 0.6 , 1.6 , - 0.9 ,
285
+ - 0.07 , 1.95 , 0.9 , - 0.2 , - 0.5 , 0.3 ,
286
+ 0.4 , - 0.37 , 0.6 ],
287
+ 'xaxis' : 'x1' ,
288
+ 'xbins' : {'end' : 1.95 , 'size' : 0.2 ,
289
+ 'start' : - 0.9 },
290
+ 'yaxis' : 'y1' }
291
+ self .assertEqual (dp ['data' ][0 ], expected_dp_data_hist_1 )
292
+
293
+ expected_dp_data_hist_2 = {'autobinx' : False ,
294
+ 'histnorm' : 'probability density' ,
295
+ 'legendgroup' : '2013' ,
296
+ 'marker' :
297
+ {'color' : 'rgb(255, 127, 14)' },
298
+ 'name' : '2013' ,
299
+ 'opacity' : 0.7 ,
300
+ 'type' : 'histogram' ,
301
+ 'x' : [0.8 , 1.5 , 1.5 , 0.6 , 0.59 , 1.0 ,
302
+ 0.8 , 1.7 , 0.5 , 0.8 , - 0.3 , 1.2 ,
303
+ 0.56 , 0.3 , 2.2 ],
304
+ 'xaxis' : 'x1' ,
305
+ 'xbins' : {'end' : 2.2 , 'size' : 0.2 ,
306
+ 'start' : - 0.3 },
307
+ 'yaxis' : 'y1' }
308
+ self .assertEqual (dp ['data' ][1 ], expected_dp_data_hist_2 )
309
+
310
+ def test_distplot_binsize_array_prob_density (self ):
155
311
hist1_x = [0.8 , 1.2 , 0.2 , 0.6 , 1.6 , - 0.9 , - 0.07 , 1.95 , 0.9 , - 0.2 ,
156
312
- 0.5 , 0.3 , 0.4 , - 0.37 , 0.6 ]
157
313
hist2_x = [0.8 , 1.5 , 1.5 , 0.6 , 0.59 , 1.0 , 0.8 , 1.7 , 0.5 , 0.8 , - 0.3 ,
@@ -167,13 +323,14 @@ def test_distplot_binsize_array(self):
167
323
expected_dp_data_hist_1 = {'autobinx' : False ,
168
324
'histnorm' : 'probability density' ,
169
325
'legendgroup' : '2012' ,
170
- 'marker' : {'color' : 'rgb(31, 119, 180)' },
326
+ 'marker' :
327
+ {'color' : 'rgb(31, 119, 180)' },
171
328
'name' : '2012' ,
172
329
'opacity' : 0.7 ,
173
330
'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 ],
331
+ 'x' : [0.8 , 1.2 , 0.2 , 0.6 , 1.6 , - 0.9 ,
332
+ - 0.07 , 1.95 , 0.9 , - 0.2 , - 0.5 , 0.3 ,
333
+ 0.4 , - 0.37 , 0.6 ],
177
334
'xaxis' : 'x1' ,
178
335
'xbins' : {'end' : 1.95 , 'size' : 0.2 ,
179
336
'start' : - 0.9 },
@@ -183,13 +340,14 @@ def test_distplot_binsize_array(self):
183
340
expected_dp_data_hist_2 = {'autobinx' : False ,
184
341
'histnorm' : 'probability density' ,
185
342
'legendgroup' : '2013' ,
186
- 'marker' : {'color' : 'rgb(255, 127, 14)' },
343
+ 'marker' :
344
+ {'color' : 'rgb(255, 127, 14)' },
187
345
'name' : '2013' ,
188
346
'opacity' : 0.7 ,
189
347
'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 ],
348
+ 'x' : [0.8 , 1.5 , 1.5 , 0.6 , 0.59 , 1.0 ,
349
+ 0.8 , 1.7 , 0.5 , 0.8 , - 0.3 , 1.2 ,
350
+ 0.56 , 0.3 , 2.2 ],
193
351
'xaxis' : 'x1' ,
194
352
'xbins' : {'end' : 2.2 , 'size' : 0.2 ,
195
353
'start' : - 0.3 },
0 commit comments