How to change the colors of the axis and tick labels of a Matplotlib plot using Python

1 min

Colors will help you a lot when visualizing data. Used properly they can drastically increase the meaning power of a plot.

There are a few ways to improve readability using colors, one of them is by changing the color of the axis and tick labels.

Here is the code

# We import our libraries
import matplotlib.pyplot as plt
import numpy as np

# Generate our sample dataset
x = np.linspace(1,100)
y = np.exp(x)

# We create a canvas with one ax
fig, axes = plt.subplots(1, 1, figsize=(8,4))

# We plot on our first axis
axes.plot(x, y, alpha=0.6, c='tab:blue')

# We change the color of the y axis labels
axes.tick_params('y', colors='tab:blue')

# We change the color of the x axis labels
axes.tick_params('x', colors='tab:red')

# We tight the layout
fig.tight_layout()

# We plot
plt.show()
How to change the colors of the axis and labels labels

The result

How to change the colors of the axis and label ticks.

As you can see we changed the color of the ticks on the x-axis and the y-axis.

Here you are! You now know how to change the colors of the axis and ticks labels of a Matplotlib plot using Python.

More on Matplotlib

If you like what you've just read and want to know more about the Matplotlib library (e.g. how to add labels, plot different types of plots, etc...) check out the other articles I wrote on the topic, just here :

Matplotlib - The Python You Need
We gathered the only Python essentials that you will probably ever need.