Skip to content

Commit ace6783

Browse files
Merge pull request #2730 from akbo/lazier-create-distplot
distplot: only compute traces that will be shown
2 parents a6fed9b + 8a66d83 commit ace6783

File tree

1 file changed

+40
-35
lines changed

1 file changed

+40
-35
lines changed

Diff for: packages/python/plotly/plotly/figure_factory/_distplot.py

+40-35
Original file line numberDiff line numberDiff line change
@@ -183,20 +183,10 @@ def create_distplot(
183183
if isinstance(bin_size, (float, int)):
184184
bin_size = [bin_size] * len(hist_data)
185185

186-
hist = _Distplot(
187-
hist_data,
188-
histnorm,
189-
group_labels,
190-
bin_size,
191-
curve_type,
192-
colors,
193-
rug_text,
194-
show_hist,
195-
show_curve,
196-
).make_hist()
186+
data = []
187+
if show_hist:
197188

198-
if curve_type == "normal":
199-
curve = _Distplot(
189+
hist = _Distplot(
200190
hist_data,
201191
histnorm,
202192
group_labels,
@@ -206,9 +196,42 @@ def create_distplot(
206196
rug_text,
207197
show_hist,
208198
show_curve,
209-
).make_normal()
210-
else:
211-
curve = _Distplot(
199+
).make_hist()
200+
201+
data.append(hist)
202+
203+
if show_curve:
204+
205+
if curve_type == "normal":
206+
curve = _Distplot(
207+
hist_data,
208+
histnorm,
209+
group_labels,
210+
bin_size,
211+
curve_type,
212+
colors,
213+
rug_text,
214+
show_hist,
215+
show_curve,
216+
).make_normal()
217+
else:
218+
curve = _Distplot(
219+
hist_data,
220+
histnorm,
221+
group_labels,
222+
bin_size,
223+
curve_type,
224+
colors,
225+
rug_text,
226+
show_hist,
227+
show_curve,
228+
).make_kde()
229+
230+
data.append(curve)
231+
232+
if show_rug:
233+
234+
rug = _Distplot(
212235
hist_data,
213236
histnorm,
214237
group_labels,
@@ -218,26 +241,8 @@ def create_distplot(
218241
rug_text,
219242
show_hist,
220243
show_curve,
221-
).make_kde()
244+
).make_rug()
222245

223-
rug = _Distplot(
224-
hist_data,
225-
histnorm,
226-
group_labels,
227-
bin_size,
228-
curve_type,
229-
colors,
230-
rug_text,
231-
show_hist,
232-
show_curve,
233-
).make_rug()
234-
235-
data = []
236-
if show_hist:
237-
data.append(hist)
238-
if show_curve:
239-
data.append(curve)
240-
if show_rug:
241246
data.append(rug)
242247
layout = graph_objs.Layout(
243248
barmode="overlay",

0 commit comments

Comments
 (0)