Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7dd20f4

Browse files
committed
distplot edits
- DRYing type validation - fix over-indentation
1 parent dfb59e7 commit 7dd20f4

File tree

1 file changed

+14
-18
lines changed

1 file changed

+14
-18
lines changed

plotly/tools.py

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,21 +1516,17 @@ def validate_distplot(hist_data, curve_type):
15161516
:raises: (PlotlyError) If curve_type is not valid (i.e. not 'kde' or
15171517
'normal').
15181518
"""
1519-
if _numpy_imported is True:
1520-
if type(hist_data[0]) not in [list, np.ndarray]:
1519+
hist_data_types = (list,)
1520+
if _numpy_imported:
1521+
hist_data_types += (np.ndarray,)
1522+
1523+
if not isinstance(hist_data[0], hist_data_types):
15211524
raise exceptions.PlotlyError("Oops, this function was written "
15221525
"to handle multiple datasets, if "
15231526
"you want to plot just one, make "
15241527
"sure your hist_data variable is "
15251528
"still a list of lists, i.e. x = "
15261529
"[1, 2, 3] -> x = [[1, 2, 3]]")
1527-
elif type(hist_data[0]) is not list:
1528-
raise exceptions.PlotlyError("Oops, this function was written "
1529-
"to handle multiple datasets, if "
1530-
"you want to plot just one, make "
1531-
"sure your hist_data variable is "
1532-
"still a list of lists, i.e. x = "
1533-
"[1, 2, 3] -> x = [[1, 2, 3]]")
15341530

15351531
curve_opts = ('kde', 'normal')
15361532
if curve_type not in curve_opts:
@@ -2453,15 +2449,15 @@ def create_distplot(hist_data, group_labels,
24532449
anchor='x1',
24542450
dtick=1))
24552451
else:
2456-
layout = graph_objs.Layout(
2457-
barmode='overlay',
2458-
hovermode='closest',
2459-
xaxis1=dict(domain=[0.0, 1.0],
2460-
anchor='y2',
2461-
zeroline=False),
2462-
yaxis1=dict(domain=[0., 1],
2463-
anchor='free',
2464-
position=0.0))
2452+
layout = graph_objs.Layout(
2453+
barmode='overlay',
2454+
hovermode='closest',
2455+
xaxis1=dict(domain=[0.0, 1.0],
2456+
anchor='y2',
2457+
zeroline=False),
2458+
yaxis1=dict(domain=[0., 1],
2459+
anchor='free',
2460+
position=0.0))
24652461

24662462
data = sum(data, [])
24672463
dist_fig = dict(data=data, layout=layout)

0 commit comments

Comments
 (0)