我正在尝试使用 matplotlib 生成一个绘图,并使用 'stix' 字体 (rcParams['mathtext.fontset'] = 'stix') 以使字体大小从文本平滑过渡到数学文本。然而,我的一些数学符号我想是斜体(标量值),有些是斜体和粗体(张量)。我不想通过使用 Latex 渲染的解决方案,然后其他事情就搞砸了。
我会给你一个描述问题的小例子:
from numpy import *
from matplotlib.pyplot import *
# Chaning font to stix
rcParams['mathtext.fontset'] = 'stix'
# Some data to constract this plotting example
datax=[0,1,2]
datay=[8,9,10]
datay2=[8,15,10]
fig, ay = subplots()
ay.plot(datax, datay, color="0.", ls='-', label= r"$F_{\alpha}$")
ay.plot(datax, datay2, color="0.", ls='-', label=r"$\mathbf{F_{\alpha}}$")
# Now add the legend with some customizations.
legend = ay.legend(loc='left', shadow=True)
#frame = legend.get_frame()
#frame.set_facecolor('0.90')
xlabel(r"x label",fontsize=18)
ylabel(r'y label', fontsize=18)
grid()
show()
Run Code Online (Sandbox Code Playgroud)
如果您运行代码,第一个标签是斜体,第二个标签是粗体。我怎样才能使第二个标签成为粗体和斜体?
需要一些更具体的mathtext参数:
from numpy import *
from matplotlib.pyplot import *
# Changing font to stix; setting specialized math font properties as directly as possible
rcParams['mathtext.fontset'] = 'custom'
rcParams['mathtext.it'] = 'STIXGeneral:italic'
rcParams['mathtext.bf'] = 'STIXGeneral:italic:bold'
# Some data to construct this plotting example
datax=[0,1,2]
datay=[8,9,10]
datay2=[8,15,10]
fig, ay = subplots()
ay.plot(datax, datay, color="0.", ls='-', label= r"$\mathit{F_{\alpha}}$")
ay.plot(datax, datay2, color="0.", ls='-', label=r"$\mathbf{F_{\alpha}}$")
# Now add the legend with some customizations.
legend = ay.legend(loc='left', shadow=True)
# Using the specialized math font again
xlabel(r"$\mathbf{x}$ label",fontsize=18)
ylabel(r'y label', fontsize=18)
grid()
show()
Run Code Online (Sandbox Code Playgroud)
请注意,我mathbf也在轴标签中使用了 。可能会将标签的其余部分更改为 STIX 字体,您可以定义非斜体非粗体大小写:请参阅“自定义字体”下的文档。
| 归档时间: |
|
| 查看次数: |
6320 次 |
| 最近记录: |