.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
- 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 - Skill path
Data Science Foundations
Learn to clean, analyze, and visualize data with Python and SQL.Includes 15 CoursesWith CertificateBeginner Friendly55 hours - Career path
Data Scientist: Machine Learning Specialist
Machine Learning Data Scientists solve problems at scale, make predictions, find patterns, and more! They use Python, SQL, and algorithms.Includes 27 CoursesWith Professional CertificationBeginner Friendly90 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