【问题标题】:Python pyplot text with square root具有平方根的 Python pyplot 文本
【发布时间】:2021-09-03 02:54:20
【问题描述】:

我正在尝试使用以下内容注释我的 pyplot:

我能够得到一个数字的平方根,我能够得到 h 平方,但是当我把它们放在一起时,我得到了一个

ValueError: cannot switch from automatic field numbering to manual field specification

知道我做错了什么吗?

import matplotlib.pyplot as plt
x = [1, 2, 3]
y = np.array([[1, 2], [3, 4], [5, 6]])
plt.plot(x, y)
t=97.35713828629935
plt.text(1,5,r'{:3.1f}% greater than $$\sqrt{0.5*$h^2$}$$'.format(t))

【问题讨论】:

    标签: python matplotlib plot text symbols


    【解决方案1】:

    问题是第二对{} 混淆了.format。使用 double {{}} 转义它们。

    plt.text(1,5,r'{:3.1f}% greater than $\sqrt{{0.5 * h^2}}$'.format(t))

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-12-23
      • 2020-10-12
      • 2018-09-23
      • 1970-01-01
      • 1970-01-01
      • 2018-12-19
      • 1970-01-01
      相关资源
      最近更新 更多