[英]How can I draw a graph or plot with 4 quadrants using Python matplotlib?
[英]How can I draw a bar graph from three different data frames using matplotlib?
我想使用matplotLib繪制一個包含三個不同數據幀的三重條形圖
index | Number
A | 110
B | 22
D | 52
index | Number
A | 100
B | 22
C | 52
index | Number
A | 90
B | 12
C | 10
我試圖使用這段代碼,但這是錯誤的,因為這些數據需要來自同一個數據幀
ax=DF1[["Number"]].DF2[["Number"]].DF3[["Number"]].plot(kind ='bar',log=True,title = "BarGraph",figsize=(15,10),legend=True,fontsize=10)
ax.set_xlabel("Index",fontsize=12)
ax.set_ylabel("Number",fontsize=12)
plt.show()
如果你願意使用seaborn,這個代碼塊適合你:
import pandas as pd
import seaborn as sns
DF1 = pd.DataFrame({'index': ['A', 'B', 'C'], 'Number': [110, 22, 52]})
DF2 = pd.DataFrame({'index': ['A', 'B', 'C'], 'Number': [100, 22, 52]})
DF3 = pd.DataFrame({'index': ['A', 'B', 'C'], 'Number': [90, 12, 10]})
DF = pd.concat([DF1, DF2, DF3])
DF['df_num'] = ['1','1','1','2','2','2','3','3','3']
sns.barplot(data = DF, x='index', y='Number', hue='df_num')
它應該產生這個情節:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.