pyggplot是ggplot的python調用(非移植),ggplot是R中使用普遍的繪圖庫。html
源碼:https://github.com/TyberiusPrime/pyggplot#pyggplot
python
Python中的R調用封裝:https://github.com/davidthaler/Python-wrapper-for-R-Forecastgit
因爲rpy2原項目託管在sourceforge已經沒法訪問,新的github鏡像:https://github.com/randy3k/rpy2github
一個rpy2的再次封裝庫:https://github.com/quadrismegistus/RpyD2shell
pyggplot是 R ggplot2 庫的封裝。使用了rpy2進行調用,將Pandas數據幀對象傳送到R中,而後使用rpy2進行調用。app
http://nbviewer.ipython.org/url/tyberiusprime.github.io/pyggplot/pyggplot%20samples.ipynb
dom
$ pip install pyggplot
You may be required to update pandas, rpy2, so you may be required to run
ui
$ pip install --upgrade pyggplot
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()
獲取pandas.DataFrame對象,而後add layers使用多個不一樣的 add_xyz functions (e.g. add_scatter).
參考 ggplot關於layers (geoms)的文檔, 而後替換 geom_* with add_*.
url
訪問: 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.
spa
(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).當 DataFrame 傳送到 R: 行索引轉爲列,經過 '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 operatorwithout actually quite pointing at what is strictly the offending value. Also, the error appears when rendering (or printing in the 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?Other ggplots' for python http://ggplot.yhathq.com/ is a port of ggplot2 for python based on matplotlib - unfortunatly not yet feature complete as of early 2015. https://github.com/sirrice/pyplot is another wrapper for ggplot closer to R's syntax, and does not rely on rpy2 - calls command line R.