8000 added tests to cover both options of histnorm · larsoner/plotly.py@e4e53ef · GitHub
[go: up one dir, main page]

Skip to content

Commit e4e53ef

Browse files
committed
added tests to cover both options of histnorm
1 parent b28b4a2 commit e4e53ef

File tree

2 files changed

+171
-13
lines changed

2 files changed

+171
-13
lines changed

plotly/tests/test_optional/test_figure_factory.py

Lines changed: 170 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ def test_unequal_data_label_length(self):
4444
self.assertRaises(PlotlyError, tls.FigureFactory.create_distplot,
4545
**kwargs)
4646

47-
def test_simple_distplot(self):
47+
def test_simple_distplot_prob_density(self):
4848

4949
# we should be able to create a single distplot with a simple dataset
5050
# and default kwargs
5151

5252
dp = tls.FigureFactory.create_distplot(hist_data=[[1, 2, 2, 3]],
53-
group_labels=['distplot'])
53+
group_labels=['distplot'],
54+
histnorm='probability density')
5455
expected_dp_layout = {'barmode': 'overlay',
5556
'hovermode': 'closest',
5657
'legend': {'traceorder': 'reversed'},
@@ -90,7 +91,53 @@ def test_simple_distplot(self):
9091
'yaxis': 'y2'}
9192
self.assertEqual(dp['data'][2], expected_dp_data_rug)
9293

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):
94141

95142
# we should be able to create a distplot with 2 datasets no
96143
# rugplot, defined bin_size, and added title
@@ -106,6 +153,7 @@ def test_distplot_more_args(self):
106153
group_labels = ['2012', '2013']
107154

108155
dp = tls.FigureFactory.create_distplot(hist_data, group_labels,
156+
histnorm='probability density',
109157
show_rug=False, bin_size=.2)
110158
dp['layout'].update(title='Dist Plot')
111159

@@ -151,7 +199,115 @@ def test_distplot_more_args(self):
151199
'yaxis': 'y1'}
152200
self.assertEqual(dp['data'][1], expected_dp_data_hist_2)
153201

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):
155311
hist1_x = [0.8, 1.2, 0.2, 0.6, 1.6, -0.9, -0.07, 1.95, 0.9, -0.2,
156312
-0.5, 0.3, 0.4, -0.37, 0.6]
157313
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):
167323
expected_dp_data_hist_1 = {'autobinx': False,
168324
'histnorm': 'probability density',
169325
'legendgroup': '2012',
170-
'marker': {'color': 'rgb(31, 119, 180)'},
326+
'marker':
327+
{'color': 'rgb(31, 119, 180)'},
171328
'name': '2012',
172329
'opacity': 0.7,
173330
'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],
177334
'xaxis': 'x1',
178335
'xbins': {'end': 1.95, 'size': 0.2,
179336
'start': -0.9},
@@ -183,13 +340,14 @@ def test_distplot_binsize_array(self):
183340
expected_dp_data_hist_2 = {'autobinx': False,
184341
'histnorm': 'probability density',
185342
'legendgroup': '2013',
186-
'marker': {'color': 'rgb(255, 127, 14)'},
343+
'marker':
344+
{'color': 'rgb(255, 127, 14)'},
187345
'name': '2013',
188346
'opacity': 0.7,
189347
'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],
193351
'xaxis': 'x1',
194352
'xbins': {'end': 2.2, 'size': 0.2,
195353
'start': -0.3},

plotly/tools.py

Lines 7265 changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4019,7 +4019,7 @@ def create_candlestick(open, high, low, close,
40194019
@staticmethod
40204020
def create_distplot(hist_data, group_labels,
40214021
bin_size=1., curve_type='kde',
4022-
colors=[], rug_text=[], histnorm='probability density',
4022+
colors=[], rug_text=[], histnorm='probability',
40234023
show_hist=True, show_curve=True,
40244024
show_rug=True):
40254025
"""

0 commit comments

Comments
 (0)
0