python - 如何在 matplotlib 标题中包含符号
问题描述
我想在 matplotlib 标题中包含符号,但以下代码不起作用。
import matplotlib.pyplot as plt
import numpy as np
N_combs=10
t1 = np.random.randint(100, size=(N_combs,2))
g1=np.random.randint(100, size=(N_combs,2))
plt.plot(range(100), np.random.randn(100, N_combs))
plt.title([rf'$\tau_c1={x} \tau_c2={y} \Delta G_{{01}}={i} \Delta G_{{01}}={j}$' for x,y in t1[0] for i,j in g1[0]])
错误:
File "<ipython-input-972-589f95b4b1cf>", line 8, in <module>
plt.title([rf'$\tau_c1={x} \tau_c2={y} \Delta G_{{01}}={i} \Delta G_{{01}}={j}$' for x,y in t1[0] for i,j in g1[0]])
File "<ipython-input-972-589f95b4b1cf>", line 8, in <listcomp>
plt.title([rf'$\tau_c1={x} \tau_c2={y} \Delta G_{{01}}={i} \Delta G_{{01}}={j}$' for x,y in t1[0] for i,j in g1[0]])
TypeError: cannot unpack non-iterable numpy.int32 object
相反,如果我使用 plt.legend,它可以工作。
解决方案
推荐阅读
- c# - c#运行python脚本并读取输出导致
- java - 在 OpenJDK 8 上启动 JavaFX 应用程序时出现 ClassNotFoundException
- python - 如何在 Spark 中正确设置 python 版本?
- javascript - 在 mongoDB 中获取错误未知组运算符'$group'
- node.js - DOCKER_BUILDKIT=1 docker build --ssh default -t atomiclib
- python - hours minutes seconds in each line in a txt file
- validation - 我正在寻找针对 Fhir 结构定义的 Fhir 资源验证
- java - 谷歌登录在詹金斯工作中的无头铬硒中不起作用
- c# - 从 MVC 项目调用 Web APi
- qt5 - 如何将交叉编译的 Qt 二进制文件从一台计算机复制到另一台计算机