Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content
No results
  • About AskPython
  • Blog
  • Contact Me
  • Free Online Developer Tools Hub
  • Home
  • Meet the Team
  • Privacy Policy
  • Python
  • Python Course for Beginners Online FREE
  • Python Tutorial – Mega Index
  • Terms and Conditions

🚀 Supercharge your YouTube channel's growth with AI.

Try YTGrowAI Free
  • Home
  • Blog
  • About AskPython
  • Python Course
  • Start Here

Rotate Tick Labels in Python Matplotlib

  • Isha BansalIsha Bansal
  • November 23, 2021
  • Matplotlib
Rotate Tick Labels in Python Matplotlib

Hey folks! This paper will show you how to rotate the tick labels in Matplotlib plots in Python.

Ticks are the values that represent data points on axes. Matplotlib automatically marks the data points on the axes, but it also allows us to create our own axes with ticks and tick labels of our own.


Rotate Tick Labels in Matplotlib

We begin by creating a normal plot and for this tutorial, we will be building the sine plot using some random x angles and plot sine values of the x values as y values.

import matplotlib.pyplot as plt
import numpy as np
plt.style.use('seaborn')
x = [0, 90, 180, 270, 360]
y = np.sin(x)
plt.plot(x,y)
plt.show()
Normal Plot Rotate Ticks Matplotlib
Normal Plot Rotate Ticks Matplotlib

Rotating the Ticks by 45deg

Let’s have a look at how to rotate the x and y axes. To modify the axis level in the graph plot, we utilize xticks() and yticks(). Both were utilized to adjust the axis independently in this case.

import matplotlib.pyplot as plt
import numpy as np
plt.style.use('seaborn')
x = [0, 90, 180, 270, 360]
y = np.sin(x)
plt.plot(x,y)
plt.xticks(rotation = 45)
plt.yticks(rotation = 45)
plt.show()
Rotated Ticks Plot Matplotlib
Rotated Ticks Plot Matplotlib

As you may notice above, the tick labels (numbers) on both the axes are now tilted to 45deg. You can play around with the number to tilt them further.

Rotate Tickets By 90deg

Another method for rotating ticks is to use gca() and tick params() to rotate both axes at the same time without using individual statements.

x = [0, 90, 180, 270, 360]
y = num.sin(x)
plt.plot(x,y)
ln = plt.gca()
ln.tick_params(axis='both', labelrotation = 90)
plt.show()
Rotated Ticks Plot Method2 Matplotlib
Rotated Ticks Plot Method2 Matplotlib

Conclusion

Congratulations! You just learned how to rotate tick labels in matplotlib plots using two different methods. Hope you enjoyed it! 😇

Liked the tutorial? In any case, I would recommend you to have a look at the tutorials mentioned below:

  1. Plot Mathematical Functions – How to Plot Math Functions in Python?
  2. Plot data from Excel Sheet using Python
  3. 3 Matplotlib Plotting Tips to Make Plotting Effective
  4. Python: Plotting Smooth Curves

Thank you for taking your time out! Hope you learned something new!! 😄


Isha Bansal
Isha Bansal

Hey there stranger!
Do check out my blogs if you are a keen learner!

Hope you like them!

Articles: 185
4 Easy Ways to Rotate lists in Python
Previous Post 4 Easy Ways to Rotate lists in Python
Next Post Numpy dot() - A Complete Guide to Vectors, Numpy, And Calculating Dot Products
Numpy dot() – A Complete Guide to Vectors, Numpy, And Calculating Dot Products

Related Posts

What Are the Different Clustering Algorithms Used?

What Are the Different Clustering Algorithms Used?

  • September 24, 2026
Python Equivalent of Histfit and Fitdist

Python Equivalent of Histfit and Fitdist

  • October 26, 2023
MATLAB Hold On Command in Python

MATLAB Hold On Command in Python

  • October 16, 2023

Partner Websites

  • GoLangDocs
  • LinuxForDevices
  • CodeForGeek

Popular Categories

  • Python Programming
  • Python Modules
  • OOPS in Python
  • Python Programming Examples
  • Strings in Python

Hall of Fame

  • Python Programming
  • OOPS in Python
  • Creating Python Modules
  • Args and Kwargs in Python
  • Python Dictionary (Dict) Tutorial
  • Python List – 15 Things You MUST Know
  • Python Set – Things You MUST Know
  • Python String Functions: Methods by Task

Important Links

  • Home
  • Python Course
  • Start Here
  • Blog
  • About AskPython
Latest posts
  • np.linalg.eig: Eigenvalues and Eigenvectors
  • What Does %s Mean in a Python Format String?
  • How to Use np.sin() in NumPy
  • cv2.imread: Load Images with OpenCV
  • pd.read_json: Read JSON Into a DataFrame

Copyright © 2026 - AskPython. All rights reserved.