【发布时间】:2020-10-21 10:35:07
【问题描述】:
我使用以下代码创建了两个图表。我需要计算每个数据点的百分比变化并将其标记在行上(例如“+20%”)。
fig = plt.figure()
ax1 = fig.add_subplot(2, 2, (1,3))
ax2 = fig.add_subplot(2, 2, (2,4))
x = [datetime.datetime(2020, 5, 1), datetime.datetime(2020, 5, 15),
datetime.datetime(2020, 6, 1), datetime.datetime(2020, 6, 15), datetime.datetime(2020, 6, 30),]
megobi2.groupby('Name').plot(x='Date', y='BMI', ax=ax1, legend=False)
#ax1.set_ylim((5,5))
ax1.yaxis.set_ticks([24, 26, 28])
ax1.xaxis.set_ticks(x)
#ax1.xaxis.set_label_text("Date")
ax1.set_title("BMI over time")
megobi2.groupby('Name').plot(x='Date', y='Weight', ax=ax2, legend=False)
ax2.yaxis.set_ticks([150, 155, 160, 170, 175, 180, 185])
ax2.xaxis.set_ticks(x)
#ax2.xaxis.set_label_text("Date")
ax2.set_title("Weight over time")
plt.subplots_adjust(left=1.3, right=2.3, bottom=0.1, top=0.5)
fig.subplots_adjust(wspace=.6)
plt.show()
【问题讨论】:
标签: python pandas matplotlib pandas-groupby