0

I'm trying to change the font size of the tick lables on the y-axis using ax.set_yticklabels(labels=ax.get_yticklabels(), Fontsize=8)

import numpy as np
import matplotlib.pyplot as plt

fig = plt.figure()
ax  = fig.add_subplot(111)

y = np.linspace(0, 100)
x_1 = y**2
x_2 = y**2 - y

my_labels = ['x_1', 'x_2']

my_data = [x_1, x_2]

my_plot = ax.boxplot(my_data, whis = 1.5, labels=my_labels, showfliers=False, patch_artist=True)
ax.set_xticklabels(labels=my_labels, rotation = 45, Fontsize=12)
ax.set_yticklabels(labels=ax.get_yticklabels(), Fontsize=8)

my_plot['boxes'][0].set_facecolor('yellow')
my_plot['boxes'][1].set_facecolor('cyan')

plt.show()

This gives me,

enter image description here

As can be seen the y-axis labels are missing. If I comment out ax.set_yticklabels(labels=ax.get_yticklabels(), Fontsize=8) I get,

enter image description here

So, how do I change the y-axis font size?

DrBwts
  • 3,470
  • 6
  • 38
  • 62
  • 1
    You need `ax.tick_params(axis='y', labelrotation=45, labelsize=12)` to rotate the labels. `ax.get_ytickslabels()` might still be empty, only to be filled in when the plot is drawn. – JohanC Jul 03 '21 at 14:22
  • I don't know why you can't get it, but you can use `get_yticks()` to get it. – r-beginners Jul 03 '21 at 14:44

0 Answers0