[英]Plot two histograms from DataFrame on the same graph, specifieng axises
我有一個DataFrame df
A B
H
8 0.899160 1
9 41.659693 7
10 336.414450 20
11 8.442857 3
12 0.848837 1
13 3.298130 2
14 3.447251 2
15 7.667236 3
17 0.831579 1
16 0.000000 0
我想在一個圖上繪制2個直方圖,因此H
- 是x軸, A
是B
- y軸。 無論我嘗試什么,例如:
x = delivered['A']
y = delivered['B']
fig = plt.figure()
ax = fig.add_subplot(111)
x.plot(kind='hist', ax=ax)
y.plot(kind='hist', ax=ax, color='red')
要么
p = df.plot(kind='hist', x=['H'])
繪制直方圖,以B
為x軸。 但我需要我的H {8,9,10,11,12,13,14,15,16,17}作為x軸!
正如@jrjc所說,問題在於我選擇了錯誤的圖形類型! 由於我已經計算了每個觀察的特征,因此需要“條形圖”。 “hist”圖適用於每次觀察時有足夠行的情況。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.