I'm trying to do a simple log plot using the matplotlib library, but I can't seem to get the x-axis ticks to have the same fontsize.
My example code is:
import numpy as np
import matplotlib.pyplot as plt
fontsize = 8
x = np.linspace(5.6e-5,6.5e-5, 120)
y = np.logspace(-10, 10, 120)
fig = plt.figure(figsize=(3.5, 2.65), constrained_layout=True)
ax = fig.gca()
ax.plot(x,y)
plt.xlabel('X label', fontsize=fontsize)
plt.ylabel('Y label', fontsize=fontsize)
ax.tick_params(axis='both', labelsize=fontsize)
plt.gca().set_yscale('log')
plt.gca().set_xscale('log')
plt.show()
And the resulting plot:
It seems the ticks on the x axis are minor ones and are not affected the way you tried. If you also provide 'both' for the which
parameter as in
plt.tick_params(axis='both', which='both', labelsize=fontsize)
it should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With