logo_learn_stats

The way to Rotate Tick Labels in Matplotlib (With Examples)

Posted on
banner 336x280

You’ll be able to virtue refer to syntax to rotate tick labels in Matplotlib plots:

#rotate x-axis tick labels
plt.xticks(rotation=45)

#rotate y-axis tick labels
plt.yticks(rotation=90)

Refer to examples display tips on how to virtue this syntax in observe.

banner 468x60

Instance 1: Rotate X-Axis Tick Labels

Refer to code presentations tips on how to rotate the x-axis tick labels in Matplotlib:

import matplotlib.pyplot as plt

#outline knowledge
x = [1, 2, 3, 4]
y = [7, 13, 24, 22]

#manufacture plot
plt.plot(x, y, colour="pink")

#rotate x-axis tick labels
plt.xticks(rotation=45)

Instance 2: Rotate Y-Axis Tick Labels

Refer to code presentations tips on how to rotate the y-axis tick labels in Matplotlib:

import matplotlib.pyplot as plt

#outline knowledge
x = [1, 2, 3, 4]
y = [7, 13, 24, 22]

#manufacture plot
plt.plot(x, y, colour="blue")

#rotate y-axis tick labels
plt.yticks(rotation=90)

Instance 3: Rotate Each Axes Tick Labels

Refer to code presentations tips on how to rotate the tick labels on each axes in Matplotlib:

import matplotlib.pyplot as plt

#outline knowledge
x = [1, 2, 3, 4]
y = [7, 13, 24, 22]

#manufacture plot
plt.plot(x, y, colour="inexperienced")

#rotate x-axis and y-axis tick labels
plt.xticks(rotation=45)
plt.yticks(rotation=90)

Spare Assets

The way to Alternate the Collection of Ticks in Matplotlib
The way to Poised Tick Labels Font Measurement in Matplotlib
The way to Take away Ticks from Matplotlib Plots

banner 336x280

Leave a Reply

Your email address will not be published. Required fields are marked *