使用Pandas&amp ;;在一个图中的5个数据帧。 Matplotlib?

时间:2016-11-07 15:38:33

标签: python pandas matplotlib plot

我有5个数据帧,它们具有相同的结构。我想将它们绘制在一个图中以供比较。我尝试过以下代码:

path1 =  C:\\Users\\amit.tyagi\\Desktop\\dumps2\\tweet_counts\\bayesian_count.csv'
path2 = 'C:\\Users\\amit.tyagi\\Desktop\\dumps2\\tweet_counts\\fixed_count.csv'
path3 = 'C:\\Users\\amit.tyagi\\Desktop\\dumps2\\tweet_counts\\skwa_count.csv'
path4 = 'C:\\Users\\amit.tyagi\\Desktop\\dumps2\\tweet_counts\\rkwa_count.csv'
path5 = 'C:\\Users\\amit.tyagi\\Desktop\\dumps2\\tweet_counts\\cetre_count.csv'


data1 = pd.read_csv(path1, names=['timestamp', 'count_bayes'])
data2 = pd.read_csv(path2, names=['timestamp', 'count_fixed'])
data3 = pd.read_csv(path3, names=['timestamp', 'count_skwa'])
data4 = pd.read_csv(path4, names=['timestamp', 'count_rkwa'])
data5 = pd.read_csv(path5, names=['timestamp', 'count_cetre'])

df12 = pd.merge(data1, data2, how='outer', on='timestamp')
df123 = pd.merge(df12, data3, how='outer', on='timestamp')
df1234 = pd.merge(df123, data4, how='outer', on='timestamp')
df12345 = pd.merge(df1234, data5, how='outer', on='timestamp')

df12345.plot()

我得到以下情节:

plot

但这不是我真正想要的。它创建了5个窗口并分别绘制它们。我希望它们都在同一轴上,即X轴(时间戳)。有人可以帮我弄清楚我犯的错误吗?

Sample data

1 个答案:

答案 0 :(得分:0)

我自己想出了解决方案。谢谢你的帮助。

Here is the plot