plotly.figure_factory.create_distplot

plotly.figure_factory.create_distplot(hist_data, group_labels, bin_size=1.0, curve_type='kde', colors=None, rug_text=None, histnorm='probability density', show_hist=True, show_curve=True, show_rug=True)

Function that creates a distplot similar to seaborn.distplot; this function is deprecated, use instead plotly.express functions, for example

>>> import plotly.express as px
>>> tips = px.data.tips()
>>> fig = px.histogram(tips, x="total_bill", y="tip", color="sex", marginal="rug",
...                    hover_data=tips.columns)
>>> fig.show()

The distplot can be composed of all or any combination of the following 3 components: (1) histogram, (2) curve: (a) kernel density estimation or (b) normal curve, and (3) rug plot. Additionally, multiple distplots (from multiple datasets) can be created in the same plot.

Parameters
  • hist_data ((list[list])) – Use list of lists to plot multiple data sets on the same plot.

  • group_labels ((list[str])) – Names for each data set.

  • bin_size ((list[float]|float)) – Size of histogram bins. Default = 1.

  • curve_type ((str)) – ‘kde’ or ‘normal’. Default = ‘kde’

  • histnorm ((str)) – ‘probability density’ or ‘probability’ Default = ‘probability density’

  • show_hist ((bool)) – Add histogram to distplot? Default = True

  • show_curve ((bool)) – Add curve to distplot? Default = True

  • show_rug ((bool)) – Add rug to distplot? Default = True

  • colors ((list[str])) – Colors for traces.

  • rug_text ((list[list])) – Hovertext values for rug_plot,

Return (dict)

Representation of a distplot figure.

Example 1: Simple distplot of 1 data set

>>> from plotly.figure_factory import create_distplot
>>> hist_data = [[1.1, 1.1, 2.5, 3.0, 3.5,
...               3.5, 4.1, 4.4, 4.5, 4.5,
...               5.0, 5.0, 5.2, 5.5, 5.5,
...               5.5, 5.5, 5.5, 6.1, 7.0]]
>>> group_labels = ['distplot example']
>>> fig = create_distplot(hist_data, group_labels)
>>> fig.show()

Example 2: Two data sets and added rug text

>>> from plotly.figure_factory import create_distplot
>>> # Add histogram data
>>> hist1_x = [0.8, 1.2, 0.2, 0.6, 1.6,
...            -0.9, -0.07, 1.95, 0.9, -0.2,
...            -0.5, 0.3, 0.4, -0.37, 0.6]
>>> hist2_x = [0.8, 1.5, 1.5, 0.6, 0.59,
...            1.0, 0.8, 1.7, 0.5, 0.8,
...            -0.3, 1.2, 0.56, 0.3, 2.2]
>>> # Group data together
>>> hist_data = [hist1_x, hist2_x]
>>> group_labels = ['2012', '2013']
>>> # Add text
>>> rug_text_1 = ['a1', 'b1', 'c1', 'd1', 'e1',
...       'f1', 'g1', 'h1', 'i1', 'j1',
...       'k1', 'l1', 'm1', 'n1', 'o1']
>>> rug_text_2 = ['a2', 'b2', 'c2', 'd2', 'e2',
...       'f2', 'g2', 'h2', 'i2', 'j2',
...       'k2', 'l2', 'm2', 'n2', 'o2']
>>> # Group text together
>>> rug_text_all = [rug_text_1, rug_text_2]
>>> # Create distplot
>>> fig = create_distplot(
...     hist_data, group_labels, rug_text=rug_text_all, bin_size=.2)
>>> # Add title
>>> fig.update_layout(title='Dist Plot') 
>>> fig.show()

Example 3: Plot with normal curve and hide rug plot

>>> from plotly.figure_factory import create_distplot
>>> import numpy as np
>>> x1 = np.random.randn(190)
>>> x2 = np.random.randn(200)+1
>>> x3 = np.random.randn(200)-1
>>> x4 = np.random.randn(210)+2
>>> hist_data = [x1, x2, x3, x4]
>>> group_labels = ['2012', '2013', '2014', '2015']
>>> fig = create_distplot(
...     hist_data, group_labels, curve_type='normal',
...     show_rug=False, bin_size=.4)

Example 4: Distplot with Pandas

>>> from plotly.figure_factory import create_distplot
>>> import numpy as np
>>> import pandas as pd
>>> df = pd.DataFrame({'2012': np.random.randn(200),
...                    '2013': np.random.randn(200)+1})
>>> fig = create_distplot([df[c] for c in df.columns], df.columns)
>>> fig.show()