我有一个方程式,我需要在图上展示。这个方程式的公式很长,所以我想把它拆分成一行不超过80个字符。在
以下是MWE:
import matplotlib.pyplot as plt
num = 25
text = (r"$RE_{%d}$ = $\frac{\left(\sum^{l_k}{q_m} -\sum^{n}{f_h}\right) - |B_t - f_h+f_g)|}{B}$") % num
fig = plt.figure()
ax = fig.add_subplot(111)
plt.scatter([0., 1.], [0., 1.])
plt.text(0.5, 0.5, text, transform=ax.transAxes)
plt.show()
如果我这样写的话,绘图是没有问题的,但是当我试图打破text
行时,我会得到各种各样的错误。在
我该怎么做?在
一种简单的可能性是只使用串联:
也可以使用三重引号的多行字符串,但需要手动替换换行符:
^{pr2}$相关问题 更多 >
编程相关推荐