J.A*_*ado 5 python matplotlib pandas
我有两个数据帧,具有唯一的x和y坐标,我想在同一个图中绘制它们.我现在在同一图中绘制两个数据帧:
plt.plot(df1['x'],df1['y'])
plt.plot(df2['x'],df2['y'])
plt.show
Run Code Online (Sandbox Code Playgroud)
但是,熊猫也有绘图功能.
df.plot()
Run Code Online (Sandbox Code Playgroud)
我怎么能实现与我的第一个例子相同但使用pandas功能?
Ian*_*anS 12
尝试:
ax = df1.plot()
df2.plot(ax=ax)
Run Code Online (Sandbox Code Playgroud)
基本上,pandas的plot函数返回matplotlib对象,然后可以将其传递给第二个数据帧.
由JACado编辑
我想补充一点,我必须为我的代码指定x和y值:
ax = df1.plot(x='Lat', y='Lon')
df2.plot(ax=ax, x='Lat', y='Lon')
Run Code Online (Sandbox Code Playgroud)