To create a histogram with a curve (distribution plot) using Plotly in Python, plotly.figure_factory module is used.
Specifically the create_distplot function.
Distplot – Plotly Histogram with Curve
In this example, we generate random data using NumPy’s random.normal function, which creates sample data from the standard normal distribution.
You can replace this with your own data.
import plotly.figure_factory as ff
import numpy as np
# Generate random data
np.random.seed(0)
data = np.random.normal(loc=0, scale=1, size=1000)
# Create histogram with curve
fig = ff.create_distplot([data], ['Data'], curve_type='normal')
# Set layout
fig.update_layout(
title='Histogram with Distribution Curve',
xaxis=dict(title='Value'),
yaxis=dict(title='Density')
)
# Display the figure
fig.show()
Output
