
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
Barchart with vertical labels in Python/Matplotlib
First, we can create bars using plt.bar and using xticks. Then, we can align the labels by setting the “vertical” or “horizontal” attributes in the “rotation” key.
Steps
Make lists, bars_heights, and bars_label, with numbers.
Make a bar plot using bar() method, with bars_heights and length of bars_label.
Get or set the current tick locations and labels of the X-axis, using xticks() with rotation='vertical' and bars_label.
To show the plot, use plt.show() method.
Example
from matplotlib import pyplot as plt bars_heights = [14, 8, 10] bars_label = ["A label", "B label", "C label"] plt.bar(range(len(bars_label)), bars_heights) plt.xticks(range(len(bars_label)), bars_label, rotation='vertical') plt.show()
Output
- Related Articles
- How to put gap between Y-axis and the first bar in a vertical barchart in Matplotlib?
- Vertical Histogram in Python and Matplotlib
- Legend with vertical line in matplotlib
- Creating a graph with date and time in axis labels with Matplotlib
- How to plot a Bar Chart with multiple labels in Matplotlib?
- Hiding major tick labels while showing minor tick labels in Matplotlib
- How to change the separation between tick labels and axis labels in Matplotlib?
- How to hide axes but keep axis-labels in 3D Plot with Matplotlib?
- Rotate xtick labels in Seaborn boxplot using Matplotlib
- Conditional removal of labels in Matplotlib pie chart
- Fill between two vertical lines in matplotlib
- Manipulation on vertical space in Matplotlib subplots
- How to show minor tick labels on a log-scale with Matplotlib?
- How to set NetworkX edge labels offset in Matplotlib?
- How can I draw inline line labels in Matplotlib?

Advertisements