- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to rotate X-axis tick labels in Pandas bar plot?
Using plt.xticks(x, labels, rotation='vertical'), we can rotate our tick’s label.
Steps
Create two lists, x, and y.
Create labels with a list of different cities.
Adjust the subplot layout parameters, where bottom = 0.15.
Add a subplot to the current figure, where nrow = 1, ncols = 2 and index = 1.
Plot the line using plt.plot(), using x and y (Step 1).
Get or set the current tick locations and labels of the X-axis. Pass no arguments to return the current values without modifying them, with x and label data.
Set or retrieve auto-scaling margins, value is 0.2.
Set the title of the figure at index 1, the title is "Horizontal tick label".
Add a subplot to the current figure, where nrow = 1, ncols = 2 and index = 2.
Plot line using plt.plot() method, using x and y (Step 1).
Get or set the current tick locations and labels of the X-axis. Pass no arguments to return the current values without modifying them, with x, label data, and rotation = ’vertical’.
Set or retrieve auto-scaling margins, value is 0.2.
Set the title of the figure at index 2, the title is "Vertical tick label".
Use plt.show() to show the figure.
Example
import matplotlib.pyplot as plt x = [1, 2, 3, 4] y = [1, 4, 9, 6] labels = ['Delhi', 'Mumbai', 'Hyderabad', 'Chennai'] plt.subplots_adjust(bottom=0.15) plt.subplot(121) plt.plot(x, y) plt.xticks(x, labels) plt.margins(0.2) plt.title("Horizontal tick label") plt.subplot(122) plt.plot(x, y) plt.xticks(x, labels, rotation='vertical') plt.margins(0.2) plt.title("Vertical tick label") plt.show()
Output
- Related Articles
- How to create a plot with tick marks between X-axis labels in base R?
- How to rotate tick labels in a subplot in Matplotlib?
- Pandas timeseries plot setting X-axis major and minor ticks and labels
- Rotate tick labels for Seaborn barplot in Matplotib
- How to change the separation between tick labels and axis labels in Matplotlib?
- How to display X-axis labels inside the plot in base R?
- How to display X-axis labels with dash in base R plot?
- Hide axis values but keep axis tick labels in matplotlib
- How to plot the X-axis labels on the upper-side of the plot in R?
- How to set Dataframe Column value as X-axis labels in Python Pandas?
- Centering x-tick labels between tick marks in Matplotlib
- How to display long X-axis labels in a bar chart using plotly in R?
- How to remove or hide X-axis labels from a Seaborn / Matplotlib plot?
- How to X-axis labels to the top of the plot using ggplot2 in R?
- How to show tick labels on top of a matplotlib plot?
