Why is my python plotting code runs so slow after I add the legend?

Viewed 119

I want to plot a scatter plot in pandas and it runs fine. But after I add the legend, it runs really slow and got stuck. Can anyone help me, please?

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()
1 Answers

Pass label="100HZ" or whatever your label is to each plotting function and call legend once at the end.

Related