我是 python 和 stackoverflow 的新手......我來自 ggplot2 R 背景,但我仍然在使用 python。我不明白為什么我在使用 matplotlib 的圖之前有一個空圖...我只有一個基本pandas系列,我想在子圖中繪制一些行,而在其他行上繪制一些行(但是我的顯示很糟糕而且我不知道為什么/如何解決它)。先感謝您!
df = organism_df.T
fig, (ax1,ax2) = plt.subplots(nrows=1,ncols=2,figsize=(5,5))
ax1 = df.iloc[[0,2,3,-1]].plot(kind='bar')
ax1.get_legend().remove()
ax1.set_title('Number of phages/bacteria interacting vs actual DB')
ax2 = df.iloc[[1,4,5,6,7]].plot(kind='bar')
ax2.get_legend().remove()
ax2.set_title('Number of different taxonomies with interactions')
plt.tight_layout()

uj5u.com熱心網友回復:
plotfrom方法pandas需要將軸作為引數給出,例如df.plot(ax=ax1, kind='bar'). 在您的示例中,首先創建圖形(由 ax1 和 ax2 組成),然后 由 plot 函式創建另一個圖形(同時覆寫原始 ax1 物件)等。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/424610.html
標籤:Python 熊猫 matplotlib
