【发布时间】:2020-01-02 10:17:48
【问题描述】:
我编写了一个简单的代码来绘制两个函数 - f(x) 和 g(x)。我的字体有问题。我已将“Times New Roman”定义为全局字体,但如果我尝试使用斜体样式 - $$,字体会发生变化。我希望函数 f(x) 和 g(x) 中的变量 x 为斜体并且在“Times New Roman”中。
Please click here for an example figure
可以看出,f中的x和legend中的g都是斜体,但不是“Times New Roman”字体。
这是我的代码,我使用的是 python 3.7。
import scipy as sy
from matplotlib import pyplot as plt
x = sy.linspace(0, 4.188, 100)
y1 = -sy.sqrt(x) - x*sy.sqrt(x) + 0.4*x**2
y2 = - sy.exp(0.25*x) + x**0.6
plt.rcParams['font.family']='Times New Roman'
fig_1 = plt.figure(1, figsize=(1.25*6.4,1.25*4.8))
chart_1 = fig_1.add_subplot(1,1,1)
chart_1.plot(x,y1, '-k', linewidth = 2, label = 'f($x$)')
chart_1.plot(x,y2, '-b', linewidth = 2, label = 'g($x$)')
chart_1.tick_params(direction='in', size=8, width=1.0, labelsize=20)
chart_1.set_xlabel('time, s', fontsize = 24)
chart_1.set_ylabel('Force, N', fontsize = 24)
chart_1.set_xlim(0,5)
chart_1.set_ylim(-4,0)
chart_1.xaxis.set_ticks_position('both')
chart_1.yaxis.set_ticks_position('both')
chart_1.legend(fontsize = '20',bbox_to_anchor=(0.85,.7), edgecolor='k', borderpad = .25)
plt.show()
这个问题有解决办法吗?
【问题讨论】:
标签: matplotlib fonts python-3.7