Reputation: 2781
I've been making lots of plots with Matplotlib for a report and I've been formatting them all the same; increasing font sizes and things. However, on some of them using exactly the same commands seems to be giving different results - the tick labels are being rendered in a bold font when I haven't told them to be.
As far as I can tell, all the relevant bits of my program (plotting bits) are the same and look like this:
fig = plt.figure()
ax = fig.add_subplot(111)
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plt.rcParams['xtick.major.pad'] = 10
plt.rcParams['ytick.major.pad'] = 10
for label in ax.get_xticklabels() + ax.get_yticklabels():
label.set_fontsize(30)
ax.set_ylabel('Normalised magnetisation (a.u.)', fontsize = 30, labelpad=15)
ax.set_xlabel('Temperature (K)', fontsize = 30, labelpad=15)
ax.set_ylim(-1.2, 1.2)
ax.set_xlim(0, 65)
plt.locator_params(axis = 'y', nbins=4)
plt.subplots_adjust(bottom=0.18, left=0.18)
plt.savefig('path/to/file', bbox_inches='tight')
All these commands are the same for multiple plots and just a few have the bold problem. Is there anything obvious I'm missing? Is there some way the way I'm manipulating my data affects the tick labels?
Many thanks.
Edit: It's only the tick labels that are problematic, not the axis labels.
Upvotes: 4
Views: 4062
Reputation: 36
I had the same problem and I solved it by changing
fig = plt.figure()
ax = fig.add_subplot(111)
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plt.rcParams['xtick.major.pad'] = 10
plt.rcParams['ytick.major.pad'] = 10
to
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plt.rcParams['xtick.major.pad'] = 10
plt.rcParams['ytick.major.pad'] = 10
fig = plt.figure()
ax = fig.add_subplot(111)
Don't ask me why ;)
Upvotes: 2