简体   繁体   English

使用python中的ggplot绘制一个带有多个数据帧的散点图

[英]Plotting one scatterplot with multiple dataframes with ggplot in python

I am trying to get data from two separate dataframes onto the same scatterplot. 我试图将两个独立数据帧的数据放到同一个散点图上。 I have seen solutions in R that use something like: 我在R中看到过使用类似的解决方案:

ggplot() + geom_point(data = df1, aes(df1.x,df2.y)) + geom_point(data = df2,aes(df2.x, df2.y))

But in python, with the ggplot module, I get errors when I try to use ggplot() with no args. 但是在python中,使用ggplot模块,当我尝试使用没有args的ggplot()时,我会收到错误。 Is this just a limitation of the module? 这仅仅是模块的限制吗? I know I can likely use another tool to do the plotting but I would prefer a ggplot solution if possible. 我知道我可能会使用其他工具来进行绘图,但如果可能的话,我更愿意使用ggplot解决方案。

My first data frame consists of Voltage information every 2 minutes and temperature information every one hour, so combining the two dataframes is not 1 to 1. Also, I would prefer to stick with Python because the rest of my solution is in python. 我的第一个数据帧包括每2分钟一次的电压信息和每一小时的温度信息,因此将两个数据帧组合起来不是1比1.另外,我更喜欢使用Python,因为我的其余解决方案都在python中。

Just giving one dataframe as argument for ggplot() and the other inside the second geom_point declaration should do the work: 只给一个数据帧作为ggplot()的参数,另一个作为第二个geom_point声明中的另一个应该做的工作:

ggplot(aes(x='x', y='y'), data=df1) + geom_point() + 
       geom_point(aes(x='x', y='y'), data=df2)

(I prefer using the column name notation, I think is more elegant, but this is just a personal preference) (我更喜欢使用列名表示法,我认为更优雅,但这只是个人偏好)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM