Python使用很多RAM在plt.ann期间

2024-10-02 12:35:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我想添加一个箭头到我的图表中的最大峰值。因为程序生成了许多具有不同最大值位置的图,所以我让程序用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会吞噬我所有的记忆。有人能帮忙吗


Tags: 程序plt箭头colorpdbeginsetaxis

热门问题