Python:Plotly .bar()
Anonymous contributor
Published May 21, 2024
Contribute to Docs
In Plotly, the .bar() method is part of the high-level interface named plotly.express. It generates charts representing categorical data with vertical bars.
Syntax
plotly.express.bar(x, y, labels, title, width, height, ...)
x: A string, integer, series, or array-like object designating the x-axis data.y: A string, integer, series, or array-like object designating the y-axis data.labels: A dictionary used for customizing labels, including column names, axis titles, hover labels, and legend entries.title: A string designating the chart title.width: An integer designating the chart width in pixels.height: An integer designating the chart height in pixels.
Note: The ellipsis (…) indicates that there can be additional optional parameters beyond those listed here.
Example
Below is an example demonstrating how to use the .bar() method to create a simple bar chart visualizing the values of items in categories a, b, c, and d:
import plotly.express as pxfig = px.bar(x=['a', 'b', 'c', 'd'], y=[1, 2, 3, 4], labels={'x':'Category', 'y':'Count'}, title='Simple Bar Chart', height=500, width=250)fig.show()
The above code produces the following output:

All contributors
- Anonymous contributor
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
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn to clean, analyze, and visualize data with Python and SQL.
- Includes 15 Courses
- With Certificate
- Beginner Friendly.55 hours