[英]how to plot an histogram with python ggplot?
我想在y軸上繪制表示TP值的直方圖,在x軸上繪制表示方法的直方圖。 特別是,我想根據“數據”列的值獲得不同的數字。
在這種情況下,我想要第一個直方圖的值為2,1、6、9、8、1,0和第二個直方圖的值為10、10、16,...
ggplot的python版本似乎與R版本略有不同。
FN FP TN TP data method
method
SS0208 18 0 80 2 A p=100 n=100 SNR=0.5 SS0208
SS0408 19 0 80 1 A p=100 n=100 SNR=0.5 SS0408
SS0206 14 9 71 6 A p=100 n=100 SNR=0.5 SS0206
SS0406 11 6 74 9 A p=100 n=100 SNR=0.5 SS0406
SS0506 12 6 74 8 A p=100 n=100 SNR=0.5 SS0506
SS0508 19 0 80 1 A p=100 n=100 SNR=0.5 SS0508
LKSC 20 0 80 0 A p=100 n=100 SNR=0.5 LKSC
SS0208 10 1 79 10 A p=100 n=100 SNR=10 SS0208
SS0408 10 0 80 10 A p=100 n=100 SNR=10 SS0408
SS0206 4 5 75 16 A p=100 n=100 SNR=10 SS0206
第一步,我嘗試僅繪制一個直方圖,但收到一個錯誤。
df = df[df.data == df.data.unique()[0]]
In [65]: ggplot() + geom_bar(df, aes(x='method', y='TP'), stat='identity')
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-65-dd47b8d85375> in <module>()
----> 1 ggplot() + geom_bar(df, aes(x='method', y='TP'), stat='identity')
TypeError: __init__() missing 2 required positional arguments: 'aesthetics' and 'data'w
In [66]:
我嘗試了不同的命令組合,但沒有解決。
一旦解決了第一個問題,我希望根據“數據”的值對直方圖進行分組。 這可能可以通過'facet_wrap'
這可能是因為您在不帶參數的情況下調用了ggplot()
(不確定是否應該這樣做。如果您這樣認為,請在http://github.com/yhat/ggplot上添加一個問題)。
無論如何,這應該起作用:
ggplot(df, aes(x='method', y='TP')) + geom_bar(stat='identity')
不幸的是,使用geom_bar進行構面尚不能正常工作(僅當所有構面都具有所有level / x值時才可以 !)-> 錯誤報告
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.