在Matplotlib中使用乳胶

时间:2017-06-14 01:41:09

标签: matplotlib

我尝试在matplot lib中使用乳胶格式,但它没有给我一行空间。这是我的代码

plt.figure(103)
plt.title('$V_x mean and fitting$')
plt.plot(vx_mean_fit[sig_fit],Sig[sig_fit],label='$Vx mean fit$')
plt.xlabel('$V_x$')
plt.ylabel('$z/d$')
plt.legend()

这是我的照片。知道为什么标题中没有空格吗? Matplotlib plot

2 个答案:

答案 0 :(得分:1)

您可以使用原始字符串:

r'$V_x mean and fitting$'

或者您可以显式地转义空格:

'$V_x\ mean\ and\ fitting$'

答案 1 :(得分:1)

通过将完整的文本放在美元符号之间,您要求它以数学模式呈现。这通常是不希望的。你真正想要的只是渲染数学模式中的公式,而不是文本的其余部分。

plt.title('$V_x$ mean and fitting')

enter image description here

请注意,如果您的公式包含反斜杠(\),您可能希望使用原始字符串,例如

plt.title(r'$V_x\cdot\frac{1}{2}$ mean and fitting')

enter image description here