Skip to main content

ggplot for python

Project description

from ggplot import *

ggplot(aes(x='date', y='beef'), data=meat) + \
    geom_point(color='lightblue') + \
    geom_line(alpha=0.25) + \
    stat_smooth(span=.05, color='black') + \
    ggtitle("Beef: It's What's for Dinner") + \
    xlab("Date") + \
    ylab("Head of Cattle Slaughtered")

What is it?

Yes, it’s another implementation of `ggplot2 <https://github.com/hadley/ggplot2>`__. One of the biggest reasons why I continue to reach for R instead of Python for data analysis is the lack of an easy to use, high level plotting package like ggplot. I’ve tried other libraries like Bockah and d3py but what I really want is ggplot2.

ggplot is just that. It’s an extremely un-pythonic package for doing exactly what ggplot2 does. The goal of the package is to mimic the ggplot2 API. This makes it super easy for people coming over from R to use, and prevents you from having to re-learn how to plot stuff.

Goals

Getting Started

Dependencies

  • matplotlib

  • pandas

  • numpy

  • scipy

  • statsmodels

Installation

# matplotlibrc from Huy Nguyen (http://www.huyng.com/posts/sane-color-scheme-for-matplotlib/)
$ curl https://github.com/yhat/ggplot/raw/master/matplotlibrc.zip > matplotlibrc.zip
$ unzip matplotlibrc.zip -d ~/
# install ggplot using pip
$ pip install ggplot

Loading ggplot

# run an Ipython shell (or don't)
$ ipython
In [1]: from ggplot import *

That’s it! You’re ready to go!

Examples

meat_lng = pd.melt(meat[['date', 'beef', 'pork', 'broilers']], id_vars='date')
ggplot(aes(x='date', y='value', colour='variable'), data=meat_lng) + \
    geom_point() + \
    stat_smooth()

geom_point

from ggplot import *
ggplot(diamonds, aes('carat', 'price')) + \
    geom_point(alpha=1/20.)

geom_hist

p = ggplot(aes(x='carat'), data=diamonds)
p + geom_hist() + ggtitle("Histogram of Diamond Carats") + labs("Carats", "Freq")

geom_density

ggplot(diamonds, aes(x='price', color='cut')) + \
    geom_density()

geom_bar

p = ggplot(mtcars, aes('cyl'))
p + geom_bar()

TODO

  • finish README

  • add matplotlibrc to build script

  • distribute on PyPi (DONE)

  • come up with better name (DONE)

  • handle NAs gracefully (DONE)

  • make aes guess what the user actually means (DONE)

  • aes:

    • size

    • se for stat_smooth (DONE)

    • fix fill/colour (color DONE)

  • geoms:

    • geom_abline (DONE)

    • geom_area (DONE)

    • geom_bar (IN PROGRESS)

    • geom_boxplot

    • geom_hline (DONE)

    • geom_ribbon (same as geom_ribbon?)

    • geom_vline (DONE)

    • stat_bin2d (DONE)

    • geom_jitter

    • stat_smooth (bug)

  • scales:

    • scale_colour_brewer

    • scale_colour_gradient

    • scale_colour_gradient2

    • scale_x_continuous

    • scale_x_discrete

    • scale_y_continuous

  • facets:

    • facet_grid (DONE)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ggplot-0.1.8.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ggplot-0.1.8-py2.7.egg (655.5 kB view details)

Uploaded Egg

File details

Details for the file ggplot-0.1.8.tar.gz.

File metadata

  • Download URL: ggplot-0.1.8.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ggplot-0.1.8.tar.gz
Algorithm Hash digest
SHA256 33f898da06d85fab32974879e1ab4c6d19ee4060fcef7724252abf85ca1760c7
MD5 7ae99bdc0969513e33e6d231350e442e
BLAKE2b-256 4d12c148ff3f724cb80f787e65ee2c21e30a43aaebe8be3225250dd05637dcef

See more details on using hashes here.

File details

Details for the file ggplot-0.1.8-py2.7.egg.

File metadata

  • Download URL: ggplot-0.1.8-py2.7.egg
  • Upload date:
  • Size: 655.5 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for ggplot-0.1.8-py2.7.egg
Algorithm Hash digest
SHA256 3a39e31b89a68664b49cb201dfdd6fcd665aba701264a84dbe1b0e6b034855a8
MD5 2ef2e3af0214dc6cd15051e4bd9da3b4
BLAKE2b-256 d3c21e9158dd154005e825705b17d950c65af57934c77c7980104475405ce653

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page