前几天看了下python语言中的ggplot包,尝试了下,发现跟R语言中的ggplot2包用法并没有区别,见代码如下:
from ggplot import *
import pandas as pd
import numpy as np
test=pd.read_csv("D:\\ML_for_Hackers-master\\02-Exploration\\data\\01_heights_weights_genders.csv")
print(ggplot(test,aes(x='Height',y='Weight',color='Gender'))+geom_point()) #加颜色的散点图,以‘Gender分开’
print(ggplot(test,aes(x='Height',y='Weight',color='Gender'))+geom_point()+geom_smooth()) #加平滑效果
ggplot(test,aes(x='Height',y='Weight',color='Gender'))+geom_point()+stat_smooth(method='loess')
ggplot(test,aes(x='Height',y='Weight',color='Gender'))+geom_point()+facet_wrap('Gender',ncol=2)
#柱形图
mpg=pd.read_csv("D:\\Users\\zhoumeixu204\\Desktop\\mpg.csv")
ggplot(mpg,aes(x="hwy",y="cty",color='year'))+geom_point(color='steelblue')+scale_x_continuous(breaks=[10,20,30]) #分四段显示 [-co,10][10,20]...
ggplot(mpg,aes(x='hwy',colour='class',fill='True'))+geom_density()
ggplot(mpg,aes('class',fill='year'))+geom_bar()
ggplot(mpg,aes('class',fill='year'))+geom_bar()+ggtitle("the hisr")
#密度曲线
ggplot(mpg,aes(x='hwy',color='class'))+geom_density()
ggplot(mpg,aes(x='hwy',colour='class',fill='True'))+geom_density()
对于不想学matplotlib的人,可以学学这个,安装很简单 easy_install ggplot