意外';在python中使用latex进行字符串格式化时,在字段名中{'
我想在latex方程式中插入文本,它实际上是绘图的标题。换句话说,下面是我正在使用的标题的python代码:意外';在python中使用latex进行字符串格式化时,在字段名中{',python,matplotlib,Python,Matplotlib,我想在latex方程式中插入文本,它实际上是绘图的标题。换句话说,下面是我正在使用的标题的python代码: import matplotlib.pyplot as plt x=8 plt.title(r"Actual time-series is $Y_t=\alpha^\top X_t + \beta^\top X_{t-{0}}$".format(x)) plt.show() 以下是我在实现上述代码时收到的错误: Traceback (most recent call last):
import matplotlib.pyplot as plt
x=8
plt.title(r"Actual time-series is $Y_t=\alpha^\top X_t + \beta^\top X_{t-{0}}$".format(x))
plt.show()
以下是我在实现上述代码时收到的错误:
Traceback (most recent call last):
File "switch_systems.py", line 419, in <module>
plt.title(r"Actual time-series is $Y_t=\alpha^\top X_t + \beta^\top X_{t-{0}}$".format(x)
ValueError: unexpected '{' in field name
回溯(最近一次呼叫最后一次):
文件“switch_systems.py”,第419行,在
plt.title(r“实际时间序列为$Y\u t=\alpha^\top X\u t+\beta^\top X{t-{0}}$”。格式(X)
ValueError:字段名中出现意外的“{”
我希望我的标题看起来像
实际时间seris是$Y\u t=\alpha^\top X\u t+\beta^\top X{t-8}$
,就像在latex中的文本一样,与用latex编写的内容完全相似。有什么诀窍吗?你需要转义文本{
通过执行{{
和}
r"Actual time-series is $Y_t=\alpha^\top X_t + \beta^\top X_{{t-{0}}}$".format(8)
导致
Actual time-series is $Y_t=\alpha^\top X_t + \beta^\top X_{t-8}$