美文网首页
ggplot2 style plotting in Python

ggplot2 style plotting in Python

作者: Liam_ml | 来源:发表于2019-01-07 15:08 被阅读37次

    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

    添加我的微信吧

    相关文章

      网友评论

          本文标题:ggplot2 style plotting in Python

          本文链接:https://www.haomeiwen.com/subject/wvyurqtx.html