<分区>
我想在 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_{{}}$
解决这个问题,但它似乎不起作用,并且我没有更多的想法。