2016-01-13 130 views
1

我正在用python(matplotlib)绘制下图。如何在python中绘制方格网格(ggplot in R)

enter image description here

我可以通过下面的代码来做到这一点的R,

ggplot(delay.with.weather, 
aes(x=pressure, y=dep.delay), na.rm = TRUE) + geom_point(na.rm = TRUE) + 
facet_grid(season ~ ., scales="free") + stat_smooth(method=lm, na.rm = TRUE) 

我艰难如下,

plt.scatter(flights_combined.pressure,flights_combined.dep_delay) 
plt.show() 

我不能按季节柱。也无法绘制回归线。有人能帮我做这些吗?

+0

[python-ggplot](http://ggplot.yhathq.com/)呢? –

+0

我正在运行anaconda ipython。无法安装软件包。 – haimen

+0

你使用熊猫数据框吗? – kazemakase

回答

0

我建议在matplotlib之上使用seaborn来实现这种可视化,因为它对Dataframes非常有效。

的分组散点图可以通过像这样实现:

grid = seaborn.FacetGrid(flights_combined, row='season') 
grid.map(plt.scatter, 'pressure', 'delay') 

FacetGrid的文档了解更多信息。

如果你想回归线您可以做他们手动(创建自己的实现plt.scatter适合和数据绘制回归线的),或者您可能能够找到一种方法,使用lmplotExample)结合FacetGrid