我有一个我认为会更频繁发生的问题。然而,在互联网上搜索了一段时间后,我无法找到解决我的问题的方法。所以事情是这样的:
对于使用 matplotlib.pyplot 创建的绘图,我想将 SI 单位微米纳入我的 xlabel 中。然而,单位微米需要是直立的。经过一番摆弄后,我获得了所需的 xlabel。
我必须生成的代码是:
import matplotlib
import matplotlib.pyplot as plt
matplotlib.rc('text', usetex = True)
params = {'text.latex.preamble': [r'\usepackage{siunitx}', r'\usepackage{cmbright}']}
plt.rcParams.update(params)
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
ax.set_xlabel('$\si{\micro \meter}$', fontsize = 16)
ax.set_ylabel("hi", fontsize = 16)
plt.savefig("test.png")
The result is shown below:
The micro meter is exactly as I want it to be. The problem however is that the font of the x and y ticks is altered. This is because of:
matplotlib.rc('text', usetex = True)
如何将字体值重置为原始值?或者如何确保引入tex时字体不改变?
As a reference, the original values I am referring to look like this:
Besides trying to revert the fonts back to their original values I also tried different methods of incorporating micro meter into my xlabel. The problem that arises here is that I it remains italic or it has a bold type setting. The micro meter I am looking for is the one given in the first figure.
我希望有人能帮助我解决这个问题。
提前感谢