How to Rotate X-Axis Tick Label Text in Matplotlib? Last Updated : 16 Jun, 2025 Comments Improve Suggest changes Like Article Like Report Rotating X-axis tick labels in Matplotlib improves readability, especially when labels are long or overlap. Angles like 45° or 90° help display dates or categories clearly. Matplotlib provides several easy ways to rotate labels at both the figure and axes levels. Let’s explore the most effective ones.Using ax.tick_params()This method belongs to the Axes object in Matplotlib and allows you to rotate X-axis tick labels using the label rotation parameter. It's a clean, efficient and scalable solution especially suited for complex figures with multiple subplots. Python import matplotlib.pyplot as plt import numpy as np x = np.arange(0, np.pi*2, 0.05) y = np.sin(x**2) fig, ax = plt.subplots() ax.plot(x, y) ax.tick_params(axis='x', labelrotation=45) plt.title('Using ax.tick_params()') plt.show() Output Explanation: A plot is created with plt.subplots() and ax.plot(x, y), X-axis labels are rotated 45° using ax.tick_params() for better readability and the plot is shown with plt.show().Using plt.xticks(rotation=...)This is a Figure-level function from matplotlib.pyplot that sets or rotates the tick labels on the X-axis. By passing the rotation argument, you can easily angle the labels without any additional complexity. Python import matplotlib.pyplot as plt import numpy as np x = np.arange(0, np.pi*2, 0.05) y = np.sin(x**2) plt.plot(x, y) plt.xticks(rotation=45) plt.title('Using plt.xticks()') plt.show() Output Explanation: A line plot of y = sin(x²) from 0 to 2π is created with plt.plot(). X-axis labels are rotated 45° using plt.xticks(), a title is set and the plot is displayed with plt.show().Using tick.set_rotation()Here, you loop through each X-axis label retrieved using ax.get_xticklabels() and manually apply rotation using tick.set_rotation(angle). This gives fine-grained control over each tick label. Python import matplotlib.pyplot as plt import numpy as np x = np.arange(0, np.pi*2, 0.05) y = np.sin(x**2) fig, ax = plt.subplots() ax.plot(x, y) # Individual tick rotation for tick in ax.get_xticklabels(): tick.set_rotation(45) plt.title('Using tick.set_rotation()') plt.show() Output Explanation: A plot of y = sin(x²) is created using ax.plot(). The X-axis tick labels are individually accessed using ax.get_xticklabels() and rotated 45° using tick.set_rotation(45). Using ax.set_xticklabels()This method sets the tick labels explicitly on the X-axis and allows you to rotate them as well. It’s part of the Axes class and replaces the existing tick labels with the ones you provide or get from get_xticks(). Python import matplotlib.pyplot as plt import numpy as np x = np.arange(0, np.pi*2, 0.05) y = np.sin(x**2) fig, ax = plt.subplots() ax.plot(x, y) ax.set_xticklabels(ax.get_xticks(), rotation=45) plt.title('Using ax.set_xticklabels()') plt.show() Output Explanation: A plot of y = sin(x²) is created, and X-axis labels are rotated 45° using ax.set_xticklabels(). This method offers label formatting control but is best used with ax.set_xticks() to ensure proper alignment.Related articlesax.tick_params()ax.set_xticklabels() Comment More infoAdvertise with us Next Article How to Rotate X-Axis Tick Label Text in Matplotlib? J jeeteshgavande30 Follow Improve Article Tags : Technical Scripter Python Technical Scripter 2020 Python-matplotlib Practice Tags : python Similar Reads How to Hide Axis Text Ticks or Tick Labels in Matplotlib? Matplotlib library in python shows axis ticks and tick labels by default. Sometimes it is important to hide these axis ticks and tick labels. In this article we will discuss some methods by which this can be done. Before that lets have a understanding about each of them:Ticks: Axes' points are marke 3 min read Rotate axis tick labels in Seaborn and Matplotlib Seaborn and Matplotlib both are commonly used libraries for data visualization in Python. Â We can draw various types of plots using Matplotlib like scatter, line, bar, histogram, and many more. On the other hand, Seaborn provides a variety of visualization patterns. It uses easy syntax and has easil 3 min read How to Set Tick Labels Font Size in Matplotlib? Prerequisite: MatplotlibMatplotlib is one of the most widely used data visualization libraries in Python. It provides a variety of ways to create high-quality 2D plots. One important aspect of making plots readable and aesthetically pleasing is formatting tick labels, including adjusting their font 3 min read Matplotlib.axis.Tick.set_label() function in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. It is an amazing visualization library in Python for 2D plots of arrays and used for working with the broader SciPy stack. Matplotlib.axis.Tick.set_label() Function The Tick.set_label() function in axis 2 min read How to change the size of axis labels in Matplotlib? Matplotlib is a Python library that helps in visualizing and customizing various plots. One of the customization you can do is to change the size of the axis labels to make reading easier. In this guide, weâll look how to adjust font size of axis labels using Matplotlib.Letâs start with a basic plot 2 min read How to rotate text in Matplotlib â Python In this article, we will learn how to rotate text in Matplotlib in Python. Out of the many parameters in matplotlib.text(), there are three main parameters that will define text rotation and how the text will be rotated. Syntax of matplotlib.text method Syntax: matplotlib.text(x=0, y=0, text='', rot 2 min read Matplotlib.axis.Tick.get_label() in Python Matplotlib is a library in Python and it is numerical â mathematical extension for NumPy library. It is an amazing visualization library in Python for 2D plots of arrays and used for working with the broader SciPy stack. matplotlib.axis.Tick.get_label() Function The Tick.get_label() function in axis 2 min read How To Adjust Position of Axis Labels in Matplotlib? Matplotlib is a powerful Python library for creating graphs and charts. By default, it places axis labels in standard positions, but sometimes you might want to move them for better readability or design. This article explains easy ways to adjust the position of axis labels in Matplotlib to make you 3 min read How to Add a Y-Axis Label to the Secondary Y-Axis in Matplotlib? Sometimes while analyzing any data through graphs we need two x or y-axis to get some more insights into the data. Matplotlib library of Python is the most popular data visualization library, and we can generate any type of plot in Matplotlib. We can create a plot that has two y-axes and can provide 4 min read How to Change the Number of Ticks in Matplotlib? Changing the number of ticks in Matplotlib improves the clarity of a plot by controlling how many tick marks appear along the axes. This can make the chart easier to read and interpret, especially when dealing with dense or sparse data. You can increase or decrease the number of ticks depending on t 2 min read Like