项目作者: has2k1

项目描述 :
Python的图形语法
高级语言: Python
项目地址: git://github.com/has2k1/plotnine.git
创建时间: 2017-04-24T19:00:44Z
项目社区:https://github.com/has2k1/plotnine

开源协议:GNU General Public License v2.0

下载


" class="reference-link">plotnine

Release
License
DOI
Build Status
Coverage

plotnine is an implementation of a grammar of graphics in Python
based on ggplot2.
The grammar allows you to compose plots by explicitly mapping variables in a
dataframe to the visual characteristics (position, color, size etc.) of objects that make up the plot.

Plotting with a grammar of graphics is powerful. Custom (and otherwise
complex) plots are easy to think about and build incrementally, while the
simple plots remain simple to create.

To learn more about how to use plotnine, check out the
documentation. Since plotnine
has an API similar to ggplot2, where it lacks in coverage the
ggplot2 documentation
may be helpful.

Example

  1. from plotnine import *
  2. from plotnine.data import mtcars

Building a complex plot piece by piece.

  1. Scatter plot

    1. (
    2. ggplot(mtcars, aes("wt", "mpg"))
    3. + geom_point()
    4. )

  2. Scatter plot colored according some variable

    1. (
    2. ggplot(mtcars, aes("wt", "mpg", color="factor(gear)"))
    3. + geom_point()
    4. )

  3. Scatter plot colored according some variable and
    smoothed with a linear model with confidence intervals.

    1. (
    2. ggplot(mtcars, aes("wt", "mpg", color="factor(gear)"))
    3. + geom_point()
    4. + stat_smooth(method="lm")
    5. )

  4. Scatter plot colored according some variable,
    smoothed with a linear model with confidence intervals and
    plotted on separate panels.

    1. (
    2. ggplot(mtcars, aes("wt", "mpg", color="factor(gear)"))
    3. + geom_point()
    4. + stat_smooth(method="lm")
    5. + facet_wrap("gear")
    6. )

  5. Adjust the themes

I) Make it playful

  1. (
  2. ggplot(mtcars, aes("wt", "mpg", color="factor(gear)"))
  3. + geom_point()
  4. + stat_smooth(method="lm")
  5. + facet_wrap("gear")
  6. + theme_xkcd()
  7. )

II) Or professional

  1. (
  2. ggplot(mtcars, aes("wt", "mpg", color="factor(gear)"))
  3. + geom_point()
  4. + stat_smooth(method="lm")
  5. + facet_wrap("gear")
  6. + theme_tufte()
  7. )

Installation

Official release

  1. # Using pip
  2. $ pip install plotnine # 1. should be sufficient for most
  3. $ pip install 'plotnine[extra]' # 2. includes extra/optional packages
  4. $ pip install 'plotnine[test]' # 3. testing
  5. $ pip install 'plotnine[doc]' # 4. generating docs
  6. $ pip install 'plotnine[dev]' # 5. development (making releases)
  7. $ pip install 'plotnine[all]' # 6. everything
  8. # Or using conda
  9. $ conda install -c conda-forge plotnine
  10. # Or using pixi
  11. $ pixi init name-of-my-project
  12. $ cd name-of-my-project
  13. $ pixi add python plotnine

Development version

  1. $ pip install git+https://github.com/has2k1/plotnine.git

Contributing

Our documentation could use some examples, but we are looking for something
a little bit special. We have two criteria:

  1. Simple looking plots that otherwise require a trick or two.
  2. Plots that are part of a data analytic narrative. That is, they provide
    some form of clarity showing off the geom, stat, … at their
    differential best.

If you come up with something that meets those criteria, we would love to
see it. See plotnine-examples.

If you discover a bug checkout the issues
if it has not been reported, yet please file an issue.

And if you can fix a bug, your contribution is welcome.

Testing

Plotnine has tests that generate images which are compared to baseline images known
to be correct. To generate images that are consistent across all systems you have
to install matplotlib from source. You can do that with pip using the command.

  1. $ pip install matplotlib --no-binary matplotlib

Otherwise there may be small differences in the text rendering that throw off the
image comparisons.