问题遇到的现象和发生背景
pyplot()在交互模式下,有没有办法设置多张图?我想做多张图一起对比
问题相关代码,请勿粘贴截图
from matplotlib import pyplot as plt
import numpy as np
import pandas as pd
path = 'G:\\python\\数据.csv'
# 使用pandas读入
data = pd.read_csv(path,encoding="unicode_escape") #读取文件中所有数据
# 按列分离数据
a= data['shijian'] #读取某两列
b=data['jicunjinshishi']
x=[]
y=[]
# 创建绘制实时损失的动态窗口
plt.ion()
# 创建循环
for i in range(0,len(a)):
if len(x)>8:
del(x[0])
del(y[0])
x.append(a[i])
y.append(b[i])
plt.ylim(395, 398)
plt.xticks(rotation=-45) # 设置x轴标签旋转角度
plt.plot(x, y) # 画出当前x列表和y列表中的值的图形
plt.pause(0.5) # 暂停一段时间,不然画的太快会卡住显示不出来
plt.clf() # 清除之前画的图
plt.ioff() # 关闭画图窗口
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
交互模式下可以显示多张图