python - 使用 matplotlib 问题显示两个数字
问题描述
我试图在两个不同的情节中同时描绘两个人物。我只得到一个数字(特别是第一个数字)。
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_excel("My excel.xlsx")
A1 = some value
A2 = value
A20 = value
Z = value
fig = plt.figure()
ax = fig.add_subplot()
ax.plot(Z,A1)
ax.plot(Z,A2)
ax.plot(Z,A3)
ax.plot(Z,A4)
ax.plot(Z,A5)
ax.plot(Z,A6)
ax.plot(Z,A20)
plt.legend(loc = 'upper left')
plt.figure()
plt.show()
fig = plt.figure()
ax.plot = fig.add_subplot()
B1 = value
B2 = value
B3 = value
B4 = value
B20 = value
ax.plt(Z,B1)
ax.plt(Z,B2)
ax.plt(Z,B20)
plt.legend(loc= 'upper left')
plt.figure()
plt.show()
我看过一个相关的帖子处理同样的问题,但无法得出结论。欢迎任何帮助。先感谢您!
解决方案
这是一个可以帮助您创建多个子图的链接:https
://matplotlib.org/stable/gallery/subplots_axes_and_figures/subplots_demo.html 我还建议使用 list 作为 plt.plot 的参数:
使用
ax.plt([Z, Z, Z], [B1, B2, B20])
代替
ax.plt(Z,B1)
ax.plt(Z,B2)
ax.plt(Z,B20)
推荐阅读
- php - 为什么在新的 xampp 安装 php 后 Json 编码返回错误?
- java - SpringCloudStream 与 Confuent 模式注册表
- java - preparedstatement.executeupdate() 中的错误
- react-native - 即使应用程序未运行或关闭,如何从 react-native-push-notification 获取通知
- mysql - SQL - 如何在多行中用逗号分割字段中的值
- ruby - Puppet Librarian 的 Vagrant Ruby 问题
- python - 有没有办法在自定义 Tensorflow 模型中找到每个类的平均精度和召回率?
- javascript - 重命名文件名所需的 JavaScript 代码
- optaplanner - 使用 optaplanner 的两梯队车辆路径问题
- c - K&R dcl 程序几乎没有检测到任何东西