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, but a straight forward 'take pandas DataFrames and shove them into R via rpy2'
approach.

Usage:
df = pandas.DataFrame({'x': numpy.uniform(size=100), 'y' = numpy.uniform(size=100), 'group' = ['A','B'] * 50})
p = pyggplot.Plot(df)
p.add_scatter('x','y', color='group')
p.render('output.png')

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's a column!. And y = 'value' doesn't 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 ' '
-> (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 Ipython notebook),
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-6.tar.gz (17.6 kB view details)

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for pyggplot-6.tar.gz
Algorithm Hash digest
SHA256 b3a507c45a6b835abfa99319afc2628ea15e26eb78442c7d48ff7f0568781f47
MD5 7462e99fcdd972f2c04f79b1de39a69c
BLAKE2b-256 6c4992df82e3c61e084068b358c0b23d436498018a905c1d38d933df4afb7213

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