Pandas.plot多个图相同的图 [英] Pandas.plot Multiple plot same figure

查看:497
本文介绍了Pandas.plot多个图相同的图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个CSV文件,我试图在同一图中绘制它们之间的比较.我已经阅读了一些有关熊猫问题的信息,这些问题不是每次都保留内存图并创建新的.人们在谈论使用斧头变种,但我不明白...

I have multiple CSV files that I am trying to plot in same the figure to have a comparison between them. I already read some information about pandas problem not keeping memory plot and creating the new one every time. People were talking about using an ax var, but I do not understand it...

现在我有:

def scatter_plot(csvfile,param,exp):
    for i in range (1,10):
        df = pd.read_csv('{}{}.csv'.format(csvfile,i))
        ax = df.plot(kind='scatter',x=param,y ='Adjusted')
        df.plot.line(x=param,y='Adjusted',ax=ax,style='b')
    plt.show()
    plt.savefig('plot/{}/{}'.format(exp,param),dpi=100)

但是它显示了十个情节,并且只保存了最后一个情节. 任何的想法?

But it's showing me ten plot and only save the last one. Any idea?

谢谢

推荐答案

结构为

  1. 创建要绘制到的轴
  2. 运行循环以填充轴
  3. 保存和/或显示(在显示之前保存)

在代码方面:

import matplotlib.pyplot as plt
import pandas as pd

ax = plt.gca()
for i in range (1,10):
    df = pd.read_csv(...)
    df.plot(..., ax=ax)
    df.plot.line(..., ax=ax)

plt.savefig(...)
plt.show()

这篇关于Pandas.plot多个图相同的图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆