【发布时间】:2016-04-01 13:11:03
【问题描述】:
我想在 matplotlib 图的图例中使用 LaTeX 写一个带有下标的变量。此类问题的一种可能代码是:
import numpy as np
import matplotlib.pyplot as plt
a, b = 1, 0
string = "({0},{1})".format(n,l)
x = np.linspace(0, 2*np.pi, 1e3)
fig = plt.figure(0)
ax = plt.subplot(111)
ax.plot(x, np.sin(x), 'b', label = r"Function for $E_{}$".format(string))
ax.legend()
plt.savefig("example_fig.png")
但是,此代码会生成一个图,其中仅使用字符串链“string”的第一个元素: Example of the problem
我尝试使用.format{string[:]} 或$E_{{}}$ 来解决这个问题,但它似乎不起作用,我没有更多的想法。
【问题讨论】:
-
"{{({0},{1})}}".format
标签: python matplotlib format latex subscript