使用pandas功能绘制多个数据框 [英] Plotting multiple dataframes using pandas functionality
本文介绍了使用pandas功能绘制多个数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个数据框,分别具有x和y坐标,我想在同一图中绘制它们. 我现在在同一图中绘制两个数据框,如下所示:
I have two dataframes, with unique x and y coordinates, and I want to plot them in the same figure. I am now plotting two dataframes in same figure as such:
plt.plot(df1['x'],df1['y'])
plt.plot(df2['x'],df2['y'])
plt.show
但是,熊猫还具有绘图功能.
However, pandas also has plotting functionality.
df.plot()
如何使用熊猫功能实现与第一个示例相同的功能?
How could I achieve the same as my first example but use the pandas functionality?
推荐答案
尝试:
ax = df1.plot()
df2.plot(ax=ax)
基本上pandas的plot函数返回matplotlib对象,然后您可以将其传递给第二个数据框.
Basically pandas' plot function returns the matplotlib object, which you can then pass to the second dataframe.
由J.A. Cado编辑
我想补充一点,我必须为我的代码指定x和y值:
I would like to add that I had to specify the x and y values for my code:
ax = df1.plot(x='Lat', y='Lon')
df2.plot(ax=ax, x='Lat', y='Lon')
这篇关于使用pandas功能绘制多个数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文