为什么在添加图例后,我的 Python 绘图代码运行速度如此之慢?

Tra*_*nda 5 python plot matplotlib pandas

我想在熊猫中绘制一个散点图,它运行良好。但是在我添加图例后,它运行得非常慢并且卡住了。任何人都可以帮助我吗?

fcdp_data_100HZ[['Second','totCNTs']].plot.scatter(x="Second", y="totCNTs",color='royalblue',s=100,alpha=0.5, ax=axes[1])
axes[1].set_title("Counts")
axes[1].grid()
axes[1].set_ylim([1,100])
axes[1].set_yscale('log')
axes[1].set_ylabel("Counts")
axes[1].legend(['100HZ'])

fcdp_data_20HZ[['Second','totCNTs']].plot.scatter(x="Second", y="totCNTs",color='coral', s=100,alpha=0.5, ax=axes[1])
axes[1].set_title("Counts")
axes[1].grid()
axes[1].set_ylim([1,100])
axes[1].set_yscale('log')
axes[1].set_ylabel("Counts")
axes[1].legend(['20HZ'])

fcdp_data_1HZ[['Second','totCNTs']].plot.scatter(x="Second", y="totCNTs",color='darkslategrey',s=100,alpha=0.5, ax=axes[1])
axes[1].set_title("Counts")
axes[1].grid()
axes[1].set_ylim([1,100])
axes[1].set_yscale('log')
axes[1].set_ylabel("Counts")
axes[1].legend(['1HZ'])
plt.show()
Run Code Online (Sandbox Code Playgroud)

Mos*_*ner 0

label="100HZ"标签或任何标签传递给每个绘图函数,并在最后调用一次图例。