1

I would like to have more control over individual x-axis labels using matplotlib. This question helped me a bit, but I still would like to do more. For instance I would like to bold, change font style and font size.

import numpy as np
import matplotlib.pyplot as plt

x = np.linspace(1,10,10)
y = x**2

fig, ax = plt.subplots(figsize=(5,5))
plt.plot(x,y)
ax.get_xticklabels()[3].set_color('red')

enter image description here

I do understand with something like the following line, I have more parameters to control, but this will change all the labels, not an individual one:

ax.set_xticklabels(x, rotation=45, weight='light')
Rob
  • 241
  • 1
  • 14

1 Answers1

1

You can still use all the functionalities

ax.get_xticklabels()[3].set_color('red')
ax.get_xticklabels()[3].set_fontsize(20)
ax.get_xticklabels()[3].set_weight("bold")
ax.get_xticklabels()[3].set_rotation(45)

The bold function does work. See the difference:

enter image description here

enter image description here

Sheldore
  • 37,862
  • 7
  • 57
  • 71