我的目标是在同一张图上绘制两个不同的图。
我的代码:
df = pd.read_csv("https://raw.githubusercontent.com/theaupoulat/vc_fundraising/master/levee2019.csv")
# format amount raised
df["amount_raised"] = (df["amount_raised"]
.str.replace("M", "000000")
.str.replace(" ", "")
.str.replace(".", "")
.str.replace("€", "")
.str.replace("NC", "0")
.str.replace('\D', '')
.astype(int)
) / 1000000
# groupby object to extract aggregate values
per_week = df.groupby("week_number")
# dataframe creation for plotting purposes
d = {'weekly_amount': per_week.amount_raised.sum(), "total_fundraisings": per_week.size()}
df_week_recap = pd.DataFrame(data=d)
#plotting
plt.figure()
ax1 = df_week_recap['weekly_amount'].plot(secondary_y = True, color = 'violet')
ax2 = df_week_recap["total_fundraisings"].plot(kind='bar', color = 'blue')
ax2.grid(True)
ax1.grid(False)
ax1.set_ylim([0,500])
plt.show()
生成了以下图:
这很奇怪,因为粉红线显示的值比条形图(检查数据)来自[同一行+ 2]。
我真的不明白matplotlib在哪里决定偏移DataFrame值。
有任何线索吗?
谢谢!