11

私は yhat のggplot ライブラリを使用しています。次の 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

現時点では、次のことを行っています (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")たが、どちらも機能していないようです。これは常に私が得るものです:

バー

私がやろうとしているのは、以下を模倣/再現することです:

試み

バーの部分を機能させる方法はありますか (または全体を)。

4

1 に答える 1

24

を使用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()

出力は次のようになります。

ここに画像の説明を入力

于 2014-03-24T03:05:58.970 に答える