ggplot2 style plotting in Python

2019-01-07  本文已影响37人  Liam_ml

R 是一门数据科学非常好的工具,但是由于一些原因还是需要学习一下其他工具,比如python,python很好,pecifically pandas and the wonderful scikit-learn

散点图

R

ggplot(mtcars , aes(x = hp , y = mpg)) +
  geom_point()

python

ggplot(mtcars , aes(x = 'hp' , y = 'mpg')) +\
    geom_point() 
image.png

箱线图

R

ggplot(mtcars , aes(x = factor(cyl) , y = mpg)) +
  geom_boxplot()

python

mtcars['cyl'] = pd.factorize(mtcars.cyl)[0]
ggplot(mtcars , aes(x = 'cyl' , y = 'mpg')) +\
  geom_boxplot()
image.png

直方图

R

ggplot(mtcars , aes(x = mpg)) +
  geom_histogram(colour = "black" , fill = "red" , bins = 10) +
  scale_x_continuous(breaks = seq(0 , 40, 5))

python

ggplot(mtcars , aes(x = 'mpg')) +\
  geom_histogram(fill = 'red' , bins = 10)
image.png

分页

R

ggplot(mtcars , aes(x = hp , y = qsec)) +
 geom_point() +
 facet_wrap(~factor(cyl))

python

ggplot(mtcars , aes(x = 'hp' , y = 'qsec')) +\
  geom_point() +\
  facet_wrap(~'cyl')

image.png

更多调整

R

ggplot(mtcars , aes(x = hp , y = mpg , colour = factor(cyl))) +
  geom_point()
image.png

python

ggplot(mtcars , aes(x = 'hp' , y = 'mpg' , color = 'name')) +\
  geom_point()
image.png

R

ggplot(diamonds , aes(x = price , fill = color)) +
  geom_histogram(colour = "black") +
  facet_wrap(~cut)

image.png

python

ggplot(diamonds , aes(x = 'price' , fill = 'color')) +\
  geom_histogram(colour = 'black') +\
  facet_wrap('cut')
image.png 米霖微信.PNG

添加我的微信吧

上一篇下一篇

猜你喜欢

热点阅读