Python在plt.annotate

时间:2016-06-14 08:08:43

标签: python python-3.x pandas matplotlib

我想在图表中的最大峰值处添加箭头。因为程序会生成大量具有最大不同位置的图形,所以我让程序用numpy的argmax()计算箭头。我用以下代码绘制了箭头:

ax3 = plt.subplot2grid((20,4), (8,0), sharex=ax1, rowspan=4, colspan=4, axisbg=color)     
ax3.plot(Data2x,Data4y,color2,label=Label4, linewidth=1.5)
ax3.set_ylim([20, 80])  
plt.grid() 
plt.xticks(rotation=0, fontsize=fontsize) 
plt.yticks(rotation=0, fontsize=fontsize)
ax3.legend(loc='upper left', fontsize= 'xx-small')

MaximumStrong = np.argmax(Data4y)
X_Axis = Data2x[MaximumStrong]
Y_Axis = Data4y[MaximumStrong]


ax3.annotate('Maximum', (X_Axis,Y_Axis),
             xytext=(Data2x[MaximumStrong+40], 70), textcoords='data',
             arrowprops={'facecolor':'k', 'arrowstyle':'->','relpos':(0.1, 0.8)},
             fontsize=6, color = 'k',
             horizontalalignment='left', verticalalignment='bottom')

Begin = pd.Timestamp("".join((dict['NumpySaveFilename'][-14:-4], ' 16:00')))
End = Begin + pd.Timedelta('14 hours')
ax3.set_xlim(Begin, End)

变量X_AxisX_Axis2pd.to_datetimeY_Axis为整数。我已经发现瓶颈在X_Axis。问题是Python吸收了我所有的记忆。有人可以帮忙吗?

0 个答案:

没有答案