python-ggplot

How to make a histogram in ipython notebook using ggplot2 (for python)

时光怂恿深爱的人放手 提交于 2019-12-04 11:00:17
问题 I'm trying to make a histogram of a simple list of numbers in python using ipython notebook and ggplot for python. Using pylab, it's easy enough, but I cannot get ggplot to work. I'm using this code (based on the diamond histogram example, which does work for me): from ggplot import * a = [1, 1, 2, 1, 1, 4, 5, 6] p = ggplot(aes(x='carat'), data=a) p + geom_hist() + ggtitle("Histogram of Diamond Carats") + labs("Carats", "Freq") Using ipython & pylab, I can make a histogram with just hist(a)

Is it possible to plot multiline chart on Python ggplot?

一笑奈何 提交于 2019-12-03 17:13:19
I need to plot 3 columns of a Pandas dataframe on python ggplot, with the same index. Is that possible? Thank you I'm assuming you want something in ggplot that replicates something like this in matplotlib. import pandas as pd df = pd.DataFrame({'a': range(10), 'b': range(5,15), 'c': range(7,17)}) df.plot() ggplot expects the data to be in 'long' format, so you need to do a little reshaping, with melt . It also currently does not support plotting the index, so that needs to made into a column. from ggplot import ggplot, geom_line, aes import pandas as pd df = pd.DataFrame({'a': range(10), 'b':

How do I create a bar chart in python ggplot?

两盒软妹~` 提交于 2019-12-03 10:20:15
问题 I'm using yhat's ggplot library. I have the following pandas DataFrame: degree observed percent observed expected percent expected 0 0 0 0.0 0 0.044551 1 1 1 0.1 1 0.138604 2 2 3 0.3 2 0.215607 3 3 4 0.4 2 0.223592 4 4 1 0.1 2 0.173905 5 5 1 0.1 1 0.108208 At the moment, I'm doing the following (where df returned in the first line in the first line in the function is the DataFrame above): def chartObservedExpected(graph): df = observedExpected(graph) return ggplot(aes(x='degree', y='percent

How do I create a bar chart in python ggplot?

烈酒焚心 提交于 2019-12-02 23:42:52
I'm using yhat's ggplot library . I have the following pandas DataFrame: degree observed percent observed expected percent expected 0 0 0 0.0 0 0.044551 1 1 1 0.1 1 0.138604 2 2 3 0.3 2 0.215607 3 3 4 0.4 2 0.223592 4 4 1 0.1 2 0.173905 5 5 1 0.1 1 0.108208 At the moment, I'm doing the following (where df returned in the first line in the first line in the function is the DataFrame above): def chartObservedExpected(graph): df = observedExpected(graph) return ggplot(aes(x='degree', y='percent observed'), data=df) + \ geom_point() + \ ylim(-0.015,1.015) + \ xlim(-0.05,max(df['degree']) + 0.25) +

How can I add a python's ggplot object to a matplot grid?

坚强是说给别人听的谎言 提交于 2019-12-01 22:53:39
My pandas DataFrame results_print has 2-dim arrays that are images. I print them like so: n_rows = results_print.shape[0] n_cols = results_print.shape[1] f, a = plt.subplots(n_cols, n_rows, figsize=(n_rows, n_cols)) methods = ['img', 'sm', 'rbd', 'ft', 'mbd', 'binary_sal', 'sal'] for r in range(n_rows): for c, cn in zip(range(len(methods)), methods): a[c][r].imshow(results_print.at[r,cn], cmap='gray') Now I created a python ggplot image object: gg = ggplot(aes(x='pixels'), data=DataFrame({'pixels': results_print.at[6,'mbd'].flatten()})) + \ geom_density(position='identity', stat='density') + \

Is there a way to plot a pandas series in ggplot?

左心房为你撑大大i 提交于 2019-11-29 00:30:16
I'm experimenting with pandas and non-matplotlib plotting. Good suggestions are here . This question regards yhat's ggplot and I am running into two issues. Plotting a series in pandas is easy. frequ.plot() I don't see how to do this in the ggplot docs. Instead I end up creating a dataframe: cheese = DataFrame({'time': frequ.index, 'count' : frequ.values}) ggplot(cheese, aes(x='time', y='count')) + geom_line() I would expect ggplot -- a project that has "tight integration with pandas" -- to have a way to plot a simple series. Second issue is I can't get stat_smooth() to display when the x axis

Is there a way to plot a pandas series in ggplot?

余生长醉 提交于 2019-11-27 15:22:07
问题 I'm experimenting with pandas and non-matplotlib plotting. Good suggestions are here. This question regards yhat's ggplot and I am running into two issues. Plotting a series in pandas is easy. frequ.plot() I don't see how to do this in the ggplot docs. Instead I end up creating a dataframe: cheese = DataFrame({'time': frequ.index, 'count' : frequ.values}) ggplot(cheese, aes(x='time', y='count')) + geom_line() I would expect ggplot -- a project that has "tight integration with pandas" -- to

pandas - multi index plotting

99封情书 提交于 2019-11-27 03:54:17
I have some data where I've manipulated the dataframe using the following code: import pandas as pd import numpy as np data = pd.DataFrame([[0,0,0,3,6,5,6,1],[1,1,1,3,4,5,2,0],[2,1,0,3,6,5,6,1],[3,0,0,2,9,4,2,1],[4,0,1,3,4,8,1,1],[5,1,1,3,3,5,9,1],[6,1,0,3,3,5,6,1],[7,0,1,3,4,8,9,1]], columns=["id", "sex", "split", "group0Low", "group0High", "group1Low", "group1High", "trim"]) data #remove all where trim == 0 trimmed = data[(data.trim == 1)] trimmed #create df with columns to be split columns = ['group0Low', 'group0High', 'group1Low', 'group1High'] to_split = trimmed[columns] to_split level