- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
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.
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()
- How to put gap between Y-axis and the first bar in a vertical barchart in Matplotlib?
- Legend with vertical line in matplotlib
- Vertical Histogram in Python and Matplotlib
- Creating a graph with date and time in axis labels with Matplotlib
- Hiding major tick labels while showing minor tick labels in Matplotlib
- How to plot a Bar Chart with multiple labels in Matplotlib?
- Fill between two vertical lines in matplotlib
- Manipulation on vertical space in Matplotlib subplots
- How to change the separation between tick labels and axis labels in Matplotlib?
- Rotate xtick labels in Seaborn boxplot using Matplotlib
- Conditional removal of labels in Matplotlib pie chart
- How to hide axes but keep axis-labels in 3D Plot with Matplotlib?
- How to show minor tick labels on a log-scale with Matplotlib?
- Vertical Buttongroup with Bootstrap
- Change grid interval and specify tick labels in Matplotlib