yhat / ggpy Goto Github PK
View Code? Open in Web Editor NEWggplot port for python
Home Page: http://yhat.github.io/ggpy/
License: BSD 2-Clause "Simplified" License
ggplot port for python
Home Page: http://yhat.github.io/ggpy/
License: BSD 2-Clause "Simplified" License
Unless something like colour or fill is set, rendered geoms should be black (and white where appropriate).
It would be nice to document each public API in ggplot and build some docs:
For the examples, we could reuse/ port ggplot2 documentation :-) These examples would also be a nice as testcase...
Not sure if the ggplot2 guys are fine with it if we copy their documentation...? @hadley
git log setup.py reveals that version did change since initial import, but there is no tags.
I advise to use 'git tag -a' to get proper annotated tags.
Does anyone know how to do this? I can't figure it out.
Is there a way to rotate labels on an axis? How would theme(axis.text.x = element_text(angle = 90, hjust = 1))
translate into Python's ggplot?
I don't know if this is possible, but I ran into a problem when trying to implement geom_boxplot, see pull request #39. I have the code commented to showcase the problem I am running into. Hopefully I am not just overlooking some simple way to access the original data frame passed into ggplot(...)
My goal is to be able to pass the whole data frame into:
http://pandas.pydata.org/pandas-docs/stable/visualization.html#box-plotting
as this is much simpler that trying to implement multiple box plots with
http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.boxplot
You can get the ggplot2 style by using mpltools:
from mpltools import style
style.use('ggplot')
Here's an example
Hi,
very nice package. I installed with pip3 install ggplot, which worked fine. However, I get the following error with "components".
Any idea what's going wrong?
Thanks >> Robert
ImportError Traceback (most recent call last)
in ()
----> 1 from ggplot import *
/usr/local/lib/python3.3/site-packages/ggplot/init.py in ()
----> 1 from .ggplot import *
2 from exampledata import *
/usr/local/lib/python3.3/site-packages/ggplot/ggplot.py in ()
5 from matplotlib.dates import DateFormatter
6 # ggplot stuff
----> 7 from components import colors, shapes, linestyles, aes
8 from components.legend import draw_legend
9 from geoms import *
ImportError: No module named 'components
I'm looking for a working example or suggestions on how to approach plotting DatetimeIndex dataframes using ggplot. I was hoping something like this might work, but haven't found a simple workaround:
ggplot(df, aes(x=df.index, y='foo')) + geom_bar()
It woule nice if the example datasets are not read in by a simple from ggplot import *
.
The easiest fix would be to remove the import in ggplot/__init__.py
and change all examples (and tests) to import both from ggplot
and ggplot/exampledata
.
Not sure if it's also possible to change the datasets to properties which only load the dataset if they are actually used.
although difficult (if not impossible ;) ) to make them thorough for graphics drawing but given Python's scripting nature, even having smoke tests would be very valuable! (e.g converting commented out example.py into a basic test battery)
Tests in matplotlib http://github.com/matplotlib/matplotlib and of plots in pandas http://github.com/pydata/pandas/blob/HEAD/pandas/tests/test_graphics.py could serve examples/ideas .
The default matplotlibrc file that you have attached has macosx as the backend which obviously doesn't work on Windows.
I just switched it to GTK and it worked fine for me.
Using Python 2.6, "import ggplot" raises a syntax error in ggplot.py (line 300) due to use of Python style dictionary comprehensions:
mapping = pd.DataFrame({
ae: data.get(key, key)
for ae, key in self.aesthetics.items()
This syntax is not backwards compatible with Python 2.X and should be converted to
mapping = pd.DataFrame(dict((ae, data.get(key, key))
for ae, key in self.aesthetics.items())
)
The same syntax is used in other places in ggplot.py and should be changed for backwards compatibility.
Legends do not always contain all of the members in the legend. Here is an example with built in data where there should be 32 although only eight get plotted. I've tried a couple of examples and the legend seems to max out at eight. Most use cases won't need 32 but I often have more than eight items in a legend.
from ggplot import *
ggplot(aes(x= 'cyl', y='mpg', colour='name'), data=mtcars) + geom_point()
matplotlibrc is preset for macOSX backend, causes problems on linux.
The size parameter of geom_line doesn't do anything. The issue is that it sets the markersize
key in layer instead of linewidth
.
So I just realizes that in addition to color being wonky with facets, all if the others discrete aesthetics are messed up -- shape, size, line type, etc.
Fix is in progress
Smoothing does not seem to produce the same results as you show in the examples. For instance, the first example in the README is:
from ggplot import *
ggplot(aes(x='date', y='beef'), data=meat) + \
geom_point(color='lightblue') + \
stat_smooth(span=.15, color='black', se=True) + \
ggtitle("Beef: It's What's for Dinner") + \
xlab("Date") + \
ylab("Head of Cattle Slaughtered")
Other example plots show similar differences in the apparent scale of smoothing and edge effects at the right side of the plot.
Thanks for creating ggplot--it looks like it is going to be a great thing!
See also the R ggsave doc http://docs.ggplot2.org/current/ggsave.html and the figsave doc http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.savefig
Set the rc params for ggplot with the matplotlib context manager. This will avoid setting ggplot specific rc params for the whole session.
This is simply great guys!
is there a way to make error bars with the current functions?
Thanks in advance,
Inti
In some case the index is quite useful as a variable, but currently can't be used. If that should be possible, these are some ideas how to implement this:
It's not a big deal, but I couldn't pip install ggplot
in a virtualenv. Tested on osx with zsh.
pip install ggplot gableroux@MacBook-Pro-de-Gabriel
Downloading/unpacking ggplot
Downloading ggplot-0.3.0.tar.gz (972kB): 972kB downloaded
Running setup.py egg_info for package ggplot
Downloading/unpacking pandas (from ggplot)
Downloading pandas-0.12.0.tar.gz (3.2MB): 3.2MB downloaded
Running setup.py egg_info for package pandas
Running from numpy source directory.
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/Users/gableroux/.virtualenvs/customEnv/build/pandas/setup.py", line 548, in <module>
**setuptools_kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 112, in setup
_setup_distribution = dist = klass(attrs)
File "build/bdist.linux-i686/egg/setuptools/dist.py", line 260, in __init__
File "build/bdist.linux-i686/egg/setuptools/dist.py", line 284, in fetch_build_eggs
File "build/bdist.linux-i686/egg/pkg_resources.py", line 563, in resolve
File "build/bdist.linux-i686/egg/pkg_resources.py", line 799, in best_match
File "build/bdist.linux-i686/egg/pkg_resources.py", line 811, in obtain
File "build/bdist.linux-i686/egg/setuptools/dist.py", line 327, in fetch_build_egg
File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 446, in easy_install
File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 476, in install_item
File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 655, in install_eggs
File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 930, in build_and_install
File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 919, in run_setup
File "build/bdist.linux-i686/egg/setuptools/sandbox.py", line 62, in run_setup
File "build/bdist.linux-i686/egg/setuptools/sandbox.py", line 105, in run
File "build/bdist.linux-i686/egg/setuptools/sandbox.py", line 64, in <lambda>
File "setup.py", line 214, in <module>
FULLVERSION += "-%s" % rev
File "setup.py", line 191, in setup_package
MICRO = 0
File "/var/folders/l2/2p5p24q16g13qxlt5smfgtfr0000gn/T/easy_install-sXT_mQ/numpy-1.7.1/numpy/distutils/core.py", line 25, in <module>
File "/var/folders/l2/2p5p24q16g13qxlt5smfgtfr0000gn/T/easy_install-sXT_mQ/numpy-1.7.1/numpy/distutils/command/build_ext.py", line 16, in <module>
File "/var/folders/l2/2p5p24q16g13qxlt5smfgtfr0000gn/T/easy_install-sXT_mQ/numpy-1.7.1/numpy/distutils/system_info.py", line 220, in <module>
File "build/bdist.linux-i686/egg/setuptools/sandbox.py", line 203, in _open
File "build/bdist.linux-i686/egg/setuptools/sandbox.py", line 199, in _violation
setuptools.sandbox.SandboxViolation: SandboxViolation: open('/dev/null', 'w') {}
The package setup script has attempted to modify files on your system
that are not within the EasyInstall build area, and has been aborted.
This package cannot be safely installed by EasyInstall, and may not
support alternate installation locations even if you run its setup
script by hand. Please inform the package's author and the EasyInstall
maintainers to find out if a fix or workaround is available.
Complete output from command python setup.py egg_info:
Running from numpy source directory.
Traceback (most recent call last):
File "<string>", line 16, in <module>
File "/Users/gableroux/.virtualenvs/customEnv/build/pandas/setup.py", line 548, in <module>
**setuptools_kwargs)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/core.py", line 112, in setup
_setup_distribution = dist = klass(attrs)
File "build/bdist.linux-i686/egg/setuptools/dist.py", line 260, in __init__
File "build/bdist.linux-i686/egg/setuptools/dist.py", line 284, in fetch_build_eggs
File "build/bdist.linux-i686/egg/pkg_resources.py", line 563, in resolve
File "build/bdist.linux-i686/egg/pkg_resources.py", line 799, in best_match
File "build/bdist.linux-i686/egg/pkg_resources.py", line 811, in obtain
File "build/bdist.linux-i686/egg/setuptools/dist.py", line 327, in fetch_build_egg
File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 446, in easy_install
File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 476, in install_item
File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 655, in install_eggs
File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 930, in build_and_install
File "build/bdist.linux-i686/egg/setuptools/command/easy_install.py", line 919, in run_setup
File "build/bdist.linux-i686/egg/setuptools/sandbox.py", line 62, in run_setup
File "build/bdist.linux-i686/egg/setuptools/sandbox.py", line 105, in run
File "build/bdist.linux-i686/egg/setuptools/sandbox.py", line 64, in <lambda>
File "setup.py", line 214, in <module>
FULLVERSION += "-%s" % rev
File "setup.py", line 191, in setup_package
MICRO = 0
File "/var/folders/l2/2p5p24q16g13qxlt5smfgtfr0000gn/T/easy_install-sXT_mQ/numpy-1.7.1/numpy/distutils/core.py", line 25, in <module>
File "/var/folders/l2/2p5p24q16g13qxlt5smfgtfr0000gn/T/easy_install-sXT_mQ/numpy-1.7.1/numpy/distutils/command/build_ext.py", line 16, in <module>
File "/var/folders/l2/2p5p24q16g13qxlt5smfgtfr0000gn/T/easy_install-sXT_mQ/numpy-1.7.1/numpy/distutils/system_info.py", line 220, in <module>
File "build/bdist.linux-i686/egg/setuptools/sandbox.py", line 203, in _open
File "build/bdist.linux-i686/egg/setuptools/sandbox.py", line 199, in _violation
setuptools.sandbox.SandboxViolation: SandboxViolation: open('/dev/null', 'w') {}
The package setup script has attempted to modify files on your system
that are not within the EasyInstall build area, and has been aborted.
This package cannot be safely installed by EasyInstall, and may not
support alternate installation locations even if you run its setup
script by hand. Please inform the package's author and the EasyInstall
maintainers to find out if a fix or workaround is available.
----------------------------------------
Command python setup.py egg_info failed with error code 1 in /Users/gableroux/.virtualenvs/customEnv/build/pandas
Thanks for the awesome module!
I've been playing around with it a bit and ran into an issue with legends in IPython Notebooks. Everything works as expected when generating figures external to the notebook (i.e., using ipython notebook
to launch the notebook), but when plotting inline (``ipython notebook --pylab inline) the legends do not appear.
I expected the legend to appear to the right hand side just as it did when plotting in a separate window.
The font for
https://github.com/yhat/ggplot/blob/master/public/img/ggplot_demo_beef.png
appears on my system to be a serif-font.
How can this be changed?
Like the title says, there seems to be no implementation for ggplot2's geom_step()
Any hope of seeing this?
First off, I love what you're doing. I've had this on a to-do list for a long time. I would love to contribute.
Ran into some initial issues. Running everything on a macbook. Tried these in the python, ipython and ipython-notebook environments; all running python 2.7.
Trying to recreate something like the first example here:
http://docs.ggplot2.org/0.9.3.1/stat_smooth.html
from ggplot import *
c = ggplot(mtcars, aes('qsec', 'wt'))
c + stat_smooth(se=True)
I got the following:
Another stat_smooth issue with one of your own examples I could not replicate from the blog post.
from ggplot import *
import pandas as pd
meat_lng = pd.melt(meat, id_vars=['date'])
p = ggplot(aes(x='date', y='value'), data=meat_lng)
gave me the following:
Any ideas?
Shape and color sourced on the same column generates two legends instead of one which is not consistent with ggplot2.
Steps to reproduce:
from ggplot import *
print ggplot(aes(x="wt", y="mpg", color = "factor(cyl)", shape = "factor(cyl)"), data=mtcars) + \
geom_point()
plt.show(1)
Actual outcome
The resulted chart unnecessary have two legends instead of a fused one like the one in the second image
Expected outcome
The legend should be only one and have the colored shapes instead:
Legend should be similar to the exemple given in the R ggplot2 documentation
http://docs.ggplot2.org/0.9.3.1/geom_point.html
To call yourself a ggplot2, you must have a grey background with white gridlines ;)
Aesthetic mappings not consistent with ggplot2 see: http://docs.ggplot2.org/0.9.3.1/geom_point.html
Steps to reproduce:
from ggplot import *
ggplot(aes(x="wt", y="mpg", color = "qsec"), data=mtcars) + \
geom_point()
plt.show(1)
Also using other data If I give a column with many different values("Volts" column) as an input for color I get the error at the end of this report.
Code here:
https://github.com/eduardflorinescu/ggplot/blob/master/examples/test_aestheticmappings.py
CSV here:
https://github.com/eduardflorinescu/ggplot/blob/master/examples/pandas_generated.csv
Notice that if I use the "category" column for color it works, if I use "Volts" I should get an aesthetic mapping instead I get the following error:
Traceback (most recent call last):
File "PythonApplication5.py", line 128, in <module>
ylab("Watts")
File "C:\PYTHON27\lib\site-packages\ggplot\ggplot.py", line 209, in __repr__
callbacks = geom.plot_layer(layer)
File "C:\PYTHON27\lib\site-packages\ggplot\geoms\geom_point.py", line 21, in plot_layer
plt.scatter(**layer)
File "C:\PYTHON27\lib\site-packages\matplotlib\pyplot.py", line 3087, in scatter
linewidths=linewidths, verts=verts, **kwargs)
File "C:\PYTHON27\lib\site-packages\matplotlib\axes.py", line 6278, in scatter
colors = mcolors.colorConverter.to_rgba_array(c, alpha)
File "C:\PYTHON27\lib\site-packages\matplotlib\colors.py", line 380, in to_rgba_array
"Cannot convert argument type %s to rgba array" % type(c))
ValueError: Cannot convert argument type <type 'numpy.ndarray'> to rgba array
I had to install Patsy under Windows to use ggplot
We need some more examples! Only a few of the geoms are showcased in the readme!
Hello,
I am using Python 2.7.5 in Linux.
Just tried the example code.
Instead of getting a graph, I got "<ggplot: (3297489)>" as outputs.
Is there a way I can debug and fix this problem?
Thanks.
Python 2.7.5 (default, May 25 2013, 00:17:53)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
from ggplot import *
print ggplot(mtcars, aes('mpg', 'qsec')) +
... geom_point(colour='steelblue') +
... scale_x_continuous(breaks=[10,20,30],
... labels=["horrible", "ok", "awesome"])
<ggplot: (3297489)>
Real-time plotting is buggy in matplotlib -- is there a way to do this using ggplot?
R has the 'factor' function: http://stat.ethz.ch/R-manual/R-devel/library/base/html/factor.html
Is there interest in implementing this so we can write:
p = ggplot(mtcars, aes(factor(cyl), mpg))
p + geom_boxplot()
instead of:
p = ggplot(mtcars, aes('factor(cyl)', mpg))
p + geom_boxplot()
Currently, when trying to install with pip on Python 3.3, the installer chokes on line 4 of ggplot/utils/utils.py
:
print plot
For every example I try (be it in IPython or not) I get the following error:
File "ggplot_test.py", line 11, in <module>
ggsave(p, "test.png")
File "C:\Python27\lib\site-packages\ggplot\utils\utils.py", line 4, in ggsave
print (plot)
File "C:\Python27\lib\site-packages\ggplot\ggplot.py", line 209, in __repr__
callbacks = geom.plot_layer(layer)
File "C:\Python27\lib\site-packages\ggplot\geoms\stat_smooth.py", line 37, in plot_layer
y, y1, y2 = smoothers.lowess(x, y)
File "C:\Python27\lib\site-packages\ggplot\components\smoothers.py", line 38, in lowess
result = smlowess(np.array(y), np.array(x), frac=span)
File "C:\Python27\lib\site-packages\statsmodels\nonparametric\smoothers_lowess.py", line 128, in lowess
exog = np.asarray(exog, float)
File "C:\Python27\lib\site-packages\numpy-1.7.0-py2.7-win32.egg\numpy\core\numeric.py", line 320, in asarray
return array(a, dtype, copy=False, order=order)
TypeError: float() argument must be a string or a number
The specific example:
from ggplot import *
p = 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")
ggsave(p, "test.png")
after cloning the repo, and then running:
python setup.py install --user
i get this traceback:
Traceback (most recent call last):
File "setup.py", line 19, in <module>
long_description=open("README.rst").read(),
IOError: [Errno 2] No such file or directory: 'README.rst'
Does stat_smooth support any method other than 'lm'? Does it support formula? It seems not. Thank you!
geom_line
ignores the group
variable for multiple series.
data = [{"gender": "m", "y": 30, "x": 10}, {"gender": "m", "y": 48, "x": 20}, {"gender": "f", "y": 20, "x": 10}, {"gender": "f", "y": 12, "x": 20}]
df = DataFrame(data)
print ggplot(df, aes(x='x', y='y', group="gender")) + geom_line()
Hello,
I packaged this neat library for PythonXY on Ubuntu.
See this PPA:
https://code.launchpad.net/~pythonxy/+archive/pythonxy-devel
Packages will be updated daily upon any changes in this github repo.
Hope to see a bit more user documentation in the future...
It is somewhat weird and I do not see any obvious reason -- if installed with 'python setup.py install' (on a Debian system and I guess on older ubuntu on travis), all .py files carry executable bit:
/usr/local/lib/python2.7/dist-packages/ggplot-0.2.8-py2.7.egg/ggplot/ggplot.py
That forbids me to submit a PR to enable travis and coverallsin support which I was testing in my clone so far
yarikoptic#1
Now it doesn't run any tests since files are executable and it would require additional --exe flag... but since there is simply smth wrong -- any clues? (I did remove shebangs from few submodule files but that wasn't it)
It would be super nice if the proper rc file could be generated automatically, to allow for this to be included as dependencies for other projects.
Facet plots don't render properly for certain layouts. (see code below)
import pylab as pl
import pandas as pd
from ggplot import *
x = np.linspace(0,.8,100)
y = x
a = [int(10*e) for e in x]
df = pd.DataFrame({'x':x, 'y':y, 'a':a})
print ggplot(aes(x='x',y='y'),df) + geom_point() + facet_wrap('a')
Is it possible to create multipage pdfs, and are there any examples?
If I try to set the figure size before, it creates the plot on figure 2, if I set the figure size on figure 2 to creates the plot on figure 3, etc
If this doesn't work:
plt.figure(num=1, figsize=(16, 10))
How can I change the figure size of the ggplot chart?
The way themes are handled might need to be changed to allow theming of some plot elements that aren't adjustable through rc params.
Need to handle edge cases better. Should add brow and nock options while I'm at it.
Basicly the same as theme_xkcd, just replace the context manager with the standard one and call style.use(style)
before copying the rcParams.
In the famous blog entry http://blog.yhathq.com/posts/ggplot-for-python.html , all seems to work now on python 3, except the last "Faceting" example.
#from http://blog.yhathq.com/posts/ggplot-for-python.html
from ggplot import *
import pandas as pd
meat_lng = pd.melt(meat, id_vars=['date'])
print( ggplot(aes(x='date', y='value'), data=meat_lng) + \
geom_point() + \
stat_smooth(colour="red") + \
facet_wrap("variable") + \
geom_hist() + facet_wrap("color"))
which gives the error
C:\Users\famille\Documents\winpython\WinPython-32bit-3.3.2.3ggplot\python-3.3.2\lib\site-packages\ggplot\geoms\facet_wrap.py in __radd__(self, gg)
16
17
---> 18 if len(x)==1:
19 n_high = 1
20 else:
TypeError: object of type 'NoneType' has no len()
I'm not sure if it's a compatibility of python 3 or something else.
Does anyone have a clue ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.