Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't fix the same fontsize for both axis ticks in a log plot [duplicate]

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: enter image description here

like image 481
T. Silva Avatar asked Oct 12 '25 01:10

T. Silva


1 Answers

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.

like image 161
Flow Avatar answered Oct 14 '25 17:10

Flow