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 port 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 ggplot2. 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

  • same API as ggplot2 for R

  • never use matplotlib again

  • ability to use both American and British English spellings of aesthetics

  • tight integration with `pandas <https://github.com/pydata/pandas>`__

  • pip installable

Getting Started

Dependencies

I realize that these are not fun to install. My best luck has always been using brew if you’re on a Mac or just using the binaries if you’re on Windows. If you’re using Linux then this should be relatively painless. You should be able to apt-get or yum all of these. - matplotlib - pandas - numpy - scipy - statsmodels

Installation

Ok the hard part is over. Installing ggplot is really easy. Just use pip! An item on the TODO is to add the matplotlibrc files to the pip installable (let me know if you’d like to help!).

# 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(color='red')

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()
meat_lng = pd.melt(meat[['date', 'beef', 'broilers', 'pork']], id_vars=['date'])
p = ggplot(aes(x='value', colour='variable', fill=True, alpha=0.3), data=meat_lng)
p + geom_density()

geom_bar

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

TODO

The list is long, but distinguished.TODO

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.9.tar.gz (15.5 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.9-py2.7.egg (665.6 kB view details)

Uploaded Egg

File details

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

File metadata

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

File hashes

Hashes for ggplot-0.1.9.tar.gz
Algorithm Hash digest
SHA256 0cf25353561c82dfe24e2bac65226d40f92f3e07f2b87482aa09368c7bf9139d
MD5 11f757ab536b4b8f8768e9feaaf79a4a
BLAKE2b-256 d26961c5320402ad88a20704f18fec45a971a077a6292edd32bc880431218d96

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ggplot-0.1.9-py2.7.egg
Algorithm Hash digest
SHA256 6274611385bb39251a416a9cb3c1861e2bafdd50ec719270fd7150a133386cfd
MD5 81633571937156a7d4cdad9b7b978a9e
BLAKE2b-256 4a0a9e4925b96f1c4af8e8083c92e33f7153ef770eeeeb599869049d4c109de5

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