我正在使用yhat的ggplot库。我有以下熊猫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
目前,我正在执行以下操作(df
函数第一行的第一行返回的是上面的DataFrame):
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) + \
labs("Degree","Proportion of Total") + \
ggtitle("Observed Node Degree Distribution")
chartObservedExpected(G)
这是我得到的:
但是,每当我尝试使用geom_bar()
而不是时geom_point()
,我最终只会得到100%的压力。我试过只是简单的geom_bar()
和也geom_bar(stat="percent observed")
,但既不似乎工作。这总是我得到的:
我想做的是模仿/复制以下内容:
知道如何使酒吧部分(或整个事情)起作用吗?
使用weight
,这是一个示例:
from ggplot import *
import pandas as pd
df = pd.DataFrame({"x":[1,2,3,4], "y":[1,3,4,2]})
ggplot(aes(x="x", weight="y"), df) + geom_bar()
输出如下:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句