那是不公平的比较。来自MWE2的情节标签从未使用过,因为没有传说;因此它不会引起任何错误。 使用后生成此图例 plt.legend() 它当然会导致与包含MathText命令的所有其他字符串所期望的相同类型的错误,并且不是原始字符串。
plt.legend()
这崩溃了:
import numpy as np import matplotlib.pyplot as plt x = np.ones(5) plt.plot(x, x, label="$\bar{x}$ (but not really)") plt.xlabel(r"$\bar{y}$ (but not really)") plt.legend() plt.show()
这不会崩溃,因为所有字符串都是原始字符串
import numpy as np import matplotlib.pyplot as plt x = np.ones(5) plt.plot(x, x, label=r"$\bar{x}$ (but not really)") plt.xlabel(r"$\bar{y}$ (but not really)") plt.legend() plt.show()