在Matplotlib图例中使用LaTex

时间:2014-04-08 16:54:21

标签: python-2.7 matplotlib

我尝试使用Matplotlib legend使用这个简单的代码注释我的图表

import numpy as np
import matplotlib.pyplot as plt

q_range = np.linspace(0.01,1,num=100)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(q_range, q_range**(-0.4))
ax.legend(r"$q^{-0.4}$")
plt.show()

为什么我的结果只是一个$符号?

1 个答案:

答案 0 :(得分:2)

指定地块的标签,然后创建图例:

import numpy as np
import matplotlib.pyplot as plt

q_range = np.linspace(0.01,1,num=100)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.plot(q_range, q_range**(-0.4), label = r"$q^{-0.4}$")
ax.legend()
plt.show()