.create_distplot()
Published Nov 23, 2024
Contribute to Docs
The .create_distplot()
function is part of Plotly’s figure_factory
module.
It generates distribution plots that combine histograms and Kernel Density Estimates (KDE), allowing for a clear visualization of a dataset’s distribution.
Syntax
fig = figure_factory.create_distplot( hist_data, group_labels, ...)
hist_data
: A list of datasets to plot. Each dataset is represented as a separate group in the distribution plot.group_labels
: List of strings corresponding to each dataset inhist_data
. These labels are used to distinguish the different groups in the plot.
Note: The ellipsis (…) in the syntax represents several optional parameters, which are automatically set to their default values, such as
bin_size=None
,curve_type='kde'
,colors=None
,histnorm=''
,show_hist=True
,show_curve=True
, andshow_rug=True
.
Example
This is a basic distribution plot that generates 2 datasets with normal distributions using default settings:
import plotly.figure_factory as ffimport numpy as npfrom scipy import stats# Generate sample data.x1 = np.random.randn(200) # Dataset 1x2 = np.random.randn(200) + 2 # Dataset 2hist_data = [x1, x2]group_labels = ['Dataset 1', 'Dataset 2']# Create the distribution plot.fig = ff.create_distplot(hist_data, group_labels)# Display the plot.fig.show()
The resulting output looks as follows:
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.
Learn Python:Plotly on Codecademy
- Career path
Computer Science
Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!Includes 6 CoursesWith Professional CertificationBeginner Friendly75 hours - Course
Learn Python 3
Learn the basics of Python 3.12, one of the most powerful, versatile, and in-demand programming languages today.With CertificateBeginner Friendly23 hours