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.2.2.tar.gz (15.6 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.2.2-py2.7.egg (665.8 kB view details)

Uploaded Egg

File details

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

File metadata

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

File hashes

Hashes for ggplot-0.2.2.tar.gz
Algorithm Hash digest
SHA256 ca6898dcd434d64c57091cce8f4c1f0600427e21e3913bfeb0ab967ec631798e
MD5 b232bdfa9aa6748ee1a23ecc3cd9e371
BLAKE2b-256 a6b52b315085cbbfb26ff87d9ea3f93479b9d05b50990270debe480aa618a8df

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for ggplot-0.2.2-py2.7.egg
Algorithm Hash digest
SHA256 41c464405bd1cf437c0d5e334416b2d3bba4d5361d043ffd906c20f49fb4c4dc
MD5 c4b5375dc623e8d33197634e1c986658
BLAKE2b-256 f770b92d6e3dfc42fbb95383506236c2c67f0ba7ed19413fc9df03cd50feb42c

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