I want to increase the ticks fontsize on a plot (both x and y axes) without passing labels as an input argument to ax.set_yticklabels()
For example, say I have the y-data below (x-data doesn't matter for this example, so you could set x=np.arange(len(y))
)
import numpy as np
import matplotlib.pylab as plt
y = np.array([ 5840.5, 3579.5, 2578. , 965.5, 748. , 485. ])
fig,ax = plt.subplots(figsize=(12,8))
plt.plot(np.arange(len(y)), y)
plt.show()
Now what I would like to do is increase the fontsize of the y-ticks, but I want to leave the labels the same and in the same location as matplotlib has created them. So I tried
ax.set_yticklabels(fontsize=20)
>>> TypeError: set_yticklabels() missing 1 required positional argument: 'labels'
which of course doesn't work. But if I pass some labels as an argument
y = np.array([ 5840.5, 3579.5, 2578. , 965.5, 748. , 485. ])
fig,ax = plt.subplots(figsize=(12,8))
plt.plot(np.arange(len(y)), y)
ax.set_yticklabels(np.arange(0,y.max(),1000), fontsize=20)
plt.show()
the fontsize does increase, but the labels and scale aren't the same as the original plot. I need to be able to change the fontsize for any array y
, not just this example given above, so passing a specific label isn't possible.
Ideally what I want looks like this: the same labels and scale as in the first plot, but the y-ticks fontsize is larger. I want to produce this plot without passing labels each time I plot, because my x and y variables are dynamic. Is there a way to do this?