Explore distributions
Inspecting the distribution of a numeric sample.
Plotly · Class
go.Histogram creates an interactive histogram trace from raw observations. Use x for vertical histograms and y for horizontal histograms.
go.Histogram is a graph-object trace that computes and displays the distribution of numeric observations. Provide values through x for a vertical histogram or through y for a horizontal one, then place the trace in a go.Figure.
go.Histogram(x=values)A Plotly graph-object histogram trace.
go.Histogram when Plotly Express is not a suitable starting point and direct graph-object control is preferred.x data sequence and pass it to a go.Figure.y produces a horizontal histogram orientation.y rather than x when the histogram should be horizontal.import numpy as np
import plotly.graph_objects as go
np.random.seed(1)
x = np.random.randn(500)
fig = go.Figure(data=[go.Histogram(x=x)])
fig.show()Creates and displays an interactive histogram from 500 normally distributed values.
Inspecting the distribution of a numeric sample.
Showing a horizontal frequency distribution.
Building a graph-object figure with explicit trace configuration.
go.Histogram used for, and how is it added to a figure?go.Histogram is the generic graph-object class for creating a histogram trace. A typical figure constructs it with an x array and passes it to go.Figure.
Follow-up: How do you make the histogram horizontal? Pass the observations with the y argument instead of x.
Use x for the usual vertical orientation. The trace aggregates those observations into histogram bins and renders the resulting distribution interactively.
Follow-up: What is the corresponding input for a horizontal histogram? Use y, which changes the orientation while retaining histogram behavior.
A histogram trace is appropriate when Plotly should perform the aggregation and counting from raw observations. If counts have already been computed, a bar trace is the more suitable representation.
Follow-up: Why not use a histogram for pre-aggregated values? Its purpose is to perform the binning and aggregation itself, whereas bars represent supplied values.
plotly.graph_objects.Figureplotly.graph_objects.Barplotly.express.histogramplotly.graph_objects.Histogram2d