matplotlib: How to use Arial-font for legend und LaTeX-mathfont for xlabel und ylabel
我想将Arial设置为Legend和图形标题,将LaTeX math-font设置为x-和y-label。
情况1:不使用
1 2 3 4 5 6 7 8 9 10 11 | import matplotlib import matplotlib.pyplot as plt legend_font = {'family' : 'Arial', 'weight' : 'normal', 'size': 23} a = [1, 2, 3] b = [1, 2, 3] plt.plot(a, b, label="Legend") plt.xlabel(r"$f/MHz$") plt.legend(prop=legend_font) plt.show() |
图例字体可以是Arial,但是xlabel的字体看起来很难看。
情况2:使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | import matplotlib import matplotlib.pyplot as plt matplotlib.rcParams['text.usetex'] = True a = [1, 2, 3] b = [1, 2, 3] plt.plot(a, b, label="Legend") plt.xlabel(r"$f/MHz$") legend_font = {'family' : 'Arial', 'weight' : 'normal', 'size': 23} plt.legend(prop=legend_font) plt.show() |

现在,xlabel的字体是正确的。 但是Legend的字体不再起作用。
我该如何解决?
谢谢你提前
在案例2代码(上面编写的第二个代码)的
1 | matplotlib.style.use('classic') |
输出量