我正在用 Python (. py 文件)编写一个脚本,并使用 Matplotlib 绘制一个数组。 我想在剧情中加入一个有公式的传说,但我还没能做到。 我以前在 IPython 或终端中也这样做过:
legend(ur'$The_formula$')
但是,当我从终端/IPython 调用. py 脚本时,这种方法不起作用。
When writing code for labels it is:
import pylab # code here pylab.plot(x,y,'f:', '$sin(x)$')
So perhaps pylab.legend('$latex here$')
pylab.legend('$latex here$')
Edit:
The u is for unicode strings, try just r'$\latex$'
u
r'$\latex$'
The easiest way is to assign the label when you plot the data, e.g.:
import matplotlib.pyplot as plt ax = plt.gca() # or any other way to get an axis object ax.plot(x, y, label=r'$\sin (x)$') ax.legend()