Plotly Histogram

In this Plotly tutorial, you will learn how to plot a histogram in Python. You can use px.histogram() function to plot a histogram.

Example 1

# Import Plotly Module
import plotly.express as px

# Data
data = [15, 19, 20, 30, 30, 30, 30, 30, 40, 40, 40, 50, 60, 70, 80]

# Histogram
plot = px.histogram(data, title='Simple Plotly Histogram', height=400, width=600)

# Show the Plot
plot.show()

Output:

Simple Plotly Histogram

Example 2

# Import Plotly Module
import plotly.express as px

# Import Dataset
dataset = px.data.gapminder().query("continent=='Oceania'")

# Histogram
plot = px.histogram(dataset, x="lifeExp", color='country', title='Plotly Histogram', height=400, width=600)

# Show the Plot
plot.show()

Output:

Plotly Histogram

Free learning resources: AiHintsCodeAllow

Leave a Comment

Your email address will not be published.