Skip to main content

A pythonic wrapper around R's ggplot

Project description

pyggplot is a Pythonic wrapper around the [R ggplot2 library](http://had.co.nz/ggplot2/).

Unlike the [Python ggplot](https://github.com/yhat/ggplot) this is not a reimplementation based on [Matplotlib](http://matplotlib.org/), but a straightforward take [Pandas](http://pandas.pydata.org/) data frames and shove them into [R](http://www.r-project.org/) via [rpy2](https://pypi.python.org/pypi/rpy2) approach.

## Examples Please visit http://nbviewer.ipython.org/url/tyberiusprime.github.io/pyggplot/pyggplot%20samples.ipynb

## Installation

The easiest installation is via [PyPI](https://pypi.python.org/pypi).

$ pip install pyggplot

You may be required to update pandas, rpy2, so you may be required to run

$ pip install –upgrade pyggplot

## Usage

import pandas as pd import numpy as np import ggplot

df = pd.DataFrame({‘x’: np.random.rand(100),

‘y’: np.random.randn(100), ‘group’: [‘A’,’B’] * 50})

p = pyggplot.Plot(df) p.add_scatter(‘x’,’y’, color=’group’) p.render(‘output.png’) ## or if you want to use it in IPython Notebook # p.render_notebook()

## Further usage

Takes a pandas.DataFrame object, then add layers with the various add_xyz functions (e.g. add_scatter).

Refer to the ggplot documentation about the layers (geoms), and simply replace geom_* with add_*. See: http://docs.ggplot2.org/0.9.3.1/index.html

You do not need to separate aesthetics from values - the wrapper will treat a parameter as value if and only if it is not a column name. (so y = 0 is a value, color = ‘blue’ is a value - except if you have a column ‘blue’, then it is a column!. And y = ‘value’ does not work, but that seems to be a ggplot issue).

When the DataFrame is passed to R:

  • row indices are turned into columns with ‘reset_index’,

  • multi level column indices are flattened by concatenating them with ‘ ‘, that is (X, ‘mean’) becomes ‘x mean’.

Error messages are not great - most of them translate to ‘one or more columns were not found’, but they can appear as a lot of different actual messages such as

  • argument “env” is missing, with no default

  • object ‘y’ not found

  • object ‘dat_0’ not found

  • requires the following missing aesthetics: x

  • non numeric argument to binary operator

without actually quite pointing at what is strictly the offending value. Also, the error appears when rendering (or printing in the [IPython Notebook](http://ipython.org/notebook.html)), not when adding the layer.

## Open questions

  • the stat support is not great - it doesn’t easily map into pythonic objects. For now, do your stats in pandas - more powerful anyhow!

  • how could error messages be improved?

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

pyggplot-20.tar.gz (19.2 kB view details)

Uploaded Source

File details

Details for the file pyggplot-20.tar.gz.

File metadata

  • Download URL: pyggplot-20.tar.gz
  • Upload date:
  • Size: 19.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for pyggplot-20.tar.gz
Algorithm Hash digest
SHA256 153c0876b902c8898037a4e33c48a1709984b0451cc4a10da95ce1436799733a
MD5 e7613b33e1e67b3f7c6d52c6a83e9e29
BLAKE2b-256 dc17ad09d95871fd2cfea5e910124fd1fe0d79f9c03b2967e526ebad5d693d6d

See more details on using hashes here.

Supported by

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