diff --git a/packages/python/plotly/plotly/figure_factory/_distplot.py b/packages/python/plotly/plotly/figure_factory/_distplot.py index 52cd08b69ab..d56e76e27b1 100644 --- a/packages/python/plotly/plotly/figure_factory/_distplot.py +++ b/packages/python/plotly/plotly/figure_factory/_distplot.py @@ -183,20 +183,10 @@ def create_distplot( if isinstance(bin_size, (float, int)): bin_size = [bin_size] * len(hist_data) - hist = _Distplot( - hist_data, - histnorm, - group_labels, - bin_size, - curve_type, - colors, - rug_text, - show_hist, - show_curve, - ).make_hist() + data = [] + if show_hist: - if curve_type == "normal": - curve = _Distplot( + hist = _Distplot( hist_data, histnorm, group_labels, @@ -206,9 +196,42 @@ def create_distplot( rug_text, show_hist, show_curve, - ).make_normal() - else: - curve = _Distplot( + ).make_hist() + + data.append(hist) + + if show_curve: + + if curve_type == "normal": + curve = _Distplot( + hist_data, + histnorm, + group_labels, + bin_size, + curve_type, + colors, + rug_text, + show_hist, + show_curve, + ).make_normal() + else: + curve = _Distplot( + hist_data, + histnorm, + group_labels, + bin_size, + curve_type, + colors, + rug_text, + show_hist, + show_curve, + ).make_kde() + + data.append(curve) + + if show_rug: + + rug = _Distplot( hist_data, histnorm, group_labels, @@ -218,26 +241,8 @@ def create_distplot( rug_text, show_hist, show_curve, - ).make_kde() + ).make_rug() - rug = _Distplot( - hist_data, - histnorm, - group_labels, - bin_size, - curve_type, - colors, - rug_text, - show_hist, - show_curve, - ).make_rug() - - data = [] - if show_hist: - data.append(hist) - if show_curve: - data.append(curve) - if show_rug: data.append(rug) layout = graph_objs.Layout( barmode="overlay",