I'm trying to make some publication-quality plots, but I have encountered a small problem. It seems by default that matplotlib axis labels and legend entries are weighted heavier than the axis tick marks. Is there anyway to force the axis labels/legend entries to be the same weight as the tick marks?
import matplotlib.pyplot as plt
import numpy as npplt.rc('text',usetex=True)
font = {'family':'serif','size':16}
plt.rc('font',**font)
plt.rc('legend',**{'fontsize':14})x = np.linspace(0,2*np.pi,100)
y = np.sin(x)fig = plt.figure(figsize=(5,5))
p1, = plt.plot(x,y)
p2, = plt.plot(x,x**2)
plt.xlabel('x-Axis')
plt.ylabel('y-Axis')
plt.legend([p1,p2],['Sin(x)','x$^2$'])
plt.gcf().subplots_adjust(left=0.2)
plt.gcf().subplots_adjust(bottom=0.15)
plt.savefig('Test.eps',bbox_inches='tight',format='eps')
plt.show()
I can use math-mode, but the problem (annoyance) is when I have a sentence for a label, i.e.,
plt.xlabel('$\mathrm{This is the x-axis}$')
which squishes it all together. I can fix it by using
plt.xlabel('$\mathrm{This\: is\: the\: x-axis}$')
but that needs a lot of punctuation. I was hoping there was something that I could change that would allow me to bypass the \mathrm{}
format, and use standard TeX format.
The other option I tried, was using \text
instead of \mathrm
, but it seems that Python's interpreter doesn't recognize this without loading the package amsmath. I have also tried:
import matplotlib
import matplotlib.pyplot as plt
import numpy as npplt.rc('text',usetex=True)
font = {'family':'serif','size':16}
plt.rc('font',**font)
plt.rc('legend',**{'fontsize':14})
matplotlib.rcParams['text.latex.preamble']=[r'\usepackage{amsmath}']x = np.linspace(0,2*np.pi,100)
y = np.sin(x)fig = plt.figure(figsize=(5,5))
p1, = plt.plot(x,y)
p2, = plt.plot(x,x**2)
plt.xlabel(r'$\text{this is the x-Axis}$')
plt.ylabel('$y-Axis$')
plt.legend([p1,p2],['Sin(x)','x$^2$'])
plt.gcf().subplots_adjust(left=0.2)
plt.gcf().subplots_adjust(bottom=0.15)
plt.savefig('Test.eps',bbox_inches='tight',format='eps')
plt.show()
This doesn't return the desired result either.