Closed as not planned
Description
The default ScalarFormatter for axes ignores font setting when used with usetex = True
.
Consider the following example, where we use latex and set the font-family to 'sans-serif':
import matplotlib.pyplot as plt
plt.rc( 'text', usetex=True )
plt.rc('font',family = 'sans-serif', size=20)
fig , ax = plt.subplots(figsize=(5,3))
ax.set_xlabel( r'\textit{x} in a.u.' )
ax.set_ylabel( r'\textit{y} in a.u.' )
plt.tight_layout()
plt.show()
As can be seen, the axis labels are in sans-serif font. However, the ticklabels are unexpectedly still in serif font.
The reason seems to be the ScalarFormatter in use. If we change the formatter to e.g. a StrMethodFormatter
, we get the expected result:
import matplotlib.pyplot as plt
import matplotlib.ticker
plt.rc( 'text', usetex=True )
plt.rc('font',family = 'sans-serif', size=20)
fig , ax = plt.subplots(figsize=(5,3))
ax.set_xlabel( r'\textit{x} in a.u.' )
ax.set_ylabel( r'\textit{y} in a.u.' )
fmt = matplotlib.ticker.StrMethodFormatter("{x}")
ax.xaxis.set_major_formatter(fmt)
plt.tight_layout()
plt.show()
Since the use of a ScalarFormatter is desirable for many applications, I think this should be fixed.