Python Visualization Package-plotnine

Source: Internet
Author: User
Tags compact ggplot
Plotnine

Csdn's edit and upload picture experience is too bad, more examples to plot-example to see.

Https://github.com/has2k1/plotnine-examples Installation website: https://plotnine.readthedocs.io/en/stable/index.html Github:https://github.com/has2k1/plotnine Ggplot2 official website: http://ggplot2.tidyverse.org/reference/index.html#section-plot-basics

Conda install-c conda-forge Plotnine # # Use

Import pandas as PD
import NumPy as NP from
plotnine import * from 
plotnine.data import *
Mpg.head (2)
Year
unnamed:0 manufacturer Model DISPL Cyl Trans DRV Cty Hwy FL class
0 1 Audi A4 1.8 1999 4 Auto (L5) F 18 29 P Compact
1 2 Audi A4 1.8 1999 4 Manual (M5) F 21st 29 P Compact
Basic Graphics

Reference to the data visualisation scatter plot in R for data science:http://r4ds.had.co.nz/data-visualisation.html

# R Writing
# (ggplot (data = mpg) + 
#  geom_point (mapping = AES (x = displ, y = Hwy))
# plotnine notation
(Ggplot (M Pg,aes (' Displ ', ' Hwy ')) +geom_point ())

# ggplot (data = mpg) + 
#  geom_point (mapping = AES (x = displ, y = Hwy, color = Class))
(Ggplot (' Mpg,aes ', ' Hwy ', color= ' class ') +geom_point ())

#ggplot (data = mpg) + 
#  geom_point (mapping = AES (x = displ, y = Hwy, size = Class))
(Ggplot mpg,aes (' Displ ', ' Hwy ', size= ' class ') +geom_point ())
# Transparency
# ggplot (data = mpg) + 
#  geom_point (mapping = AES (x = displ, y = Hwy, alpha = Class))
(Ggplot (M Pg,aes (' Displ ', ' Hwy ', alpha= ' class ')) +geom_point ())

<ggplot: (143520728433) >
#
#ggplot of different characters (data = mpg) + 
#  geom_point (mapping = AES (x = displ, y = Hwy, Shape = Class))
(Ggplot S (' Displ ', ' Hwy ', shape= ' class ')) +geom_point ())

<ggplot: (143521318874) >
#ggplot (data = mpg) + 
#  geom_point (mapping = AES (x = displ, y = Hwy), color = "Blue")
(Ggplot (' Mpg,aes ', ' Hwy ')
 +geom_point (color= ' Blue '))

<ggplot: ( -9223371893333956145) >
Panel Diagram
#ggplot (data = mpg) + 
#  geom_point (mapping = AES (x = displ, y = Hwy)) + 
#  Facet_wrap (~ class, Nrow = 2 )
(Ggplot (Mpg,aes (' Displ ', ' Hwy '))
 +geom_point ()
 +facet_wrap (' ~ class ', Nrow = 2))

<ggplot: ( -9223371893333857329) >
#ggplot (data = mpg) + 
#  geom_point (mapping = AES (x = displ, y = Hwy)) + 
#  Facet_grid (DRV ~ cyl)
(Ggplo T (Mpg,aes (' Displ ', ' Hwy '))
 +geom_point ()
 +facet_wrap (' ~ drv + cyl '))

<ggplot: ( -9223371893334132974) >
Fitting Curve

There are some questions

#ggplot (data = mpg) + 
#  Geom_smooth (mapping = AES (x = displ, y = Hwy))
(Ggplot (Mpg,aes (' Displ ', ' Hwy ')) 
  +geom_point ()
 +geom_smooth (Mapping=aes (' Displ ', ' Hwy '))
D:\anaconda3\lib\site-packages\plotnine\stats\smoothers.py:150:userwarning:confidence intervals are not yet Implementedfor lowess smoothings.
  Warnings.warn ("Confidence intervals are not yet implemented"

<ggplot: (143520360694) >
Columnar Chart
#ggplot (data = diamonds) + 
#  Geom_bar (mapping = AES (x = Cut))
(Ggplot (MPG)
 +geom_bar (Mapping=aes (' Displ '))

<ggplot: ( -9223371893334758340) >
(Ggplot (MPG)
 +stat_count (Mapping=aes (' Displ '))

<ggplot: (143521000803) >
(Ggplot (data = mpg) + 
  geom_bar (mapping = AES (' displ ', fill = ' class '), position= ' Fill '))
D:\anaconda3\lib\site-packages\plotnine\positions\position.py:194:userwarning:position_fill requires non-overlapping x Intervals
  warn (Msg.format (cls.__name__))

<ggplot: ( -9223371893334407676) >
(Ggplot (data = mpg) + 
  geom_bar (mapping = AES (' displ ', fill = ' class '), position= ' Dodge '))
D:\anaconda3\lib\site-packages\plotnine\positions\position.py:194:userwarning:position_dodge requires non-overlapping x Intervals
  warn (Msg.format (cls.__name__))

<ggplot: ( -9223371893333687145) >
(Ggplot (MPG) + 
  geom_point (mapping = AES (' Displ ', ' Hwy '), Position = "jitter"))

<ggplot: (143521035633) >
Box Line Diagram
(Ggplot (Mpg,aes (' class ', ' Hwy ')) + 
  Geom_boxplot ())

<ggplot: (143521206683) >
#ggplot (data = mpg, mapping = AES (x = class, y = Hwy)) + 
#  Geom_boxplot () +
#  Coord_flip ()

(Ggplot ( Mpg,aes (' class ', ' Hwy ')) 
 + geom_boxplot ()
 + coord_flip ())

<ggplot: ( -9223371893333525721) >
# bar <-ggplot (data = diamonds) + 
#  Geom_bar (
#    mapping = AES (x = cut, fill = cut), 
#    Show.leg End = FALSE,
#    width = 1
#  ) + 
#  Theme (Aspect.ratio = 1) +
#  Labs (x = null, y = null) c14/># Bar + coord_flip ()
# Bar + coord_polar ()

(Ggplot (MPG) 
 + geom_bar (Mapping=aes (' class ', fill= ') Class ')
 + coord_flip ())

<ggplot: ( -9223371893333735999) >
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.