2017-06-14 68 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