2017-06-14 118 views
0

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

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

+1

尝试使用原始字符串为您的文字,像'r'$ V_x的意思是和适合$''。 –

+0

这个完美的作品。 –

回答

2

您可以使用原始字符串:

r'$V_x mean and fitting$' 

或者你可以明确地转义空格:

'$V_x\ mean\ and\ fitting$' 
+0

使用原始字符串对空格不起作用。此外,你不能“逃避”空间;相反,反斜杠('\')**是乳胶数学模式中的一个空格。为了使用反斜杠,你需要使用一个原始字符串。 – ImportanceOfBeingErnest

2

通过把完整的文本在美元的符号你问它之间以数学模式呈现。这通常是不受欢迎的。你真正想要的可能只是在mathmode中渲染公式,而不是文本的其余部分。

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