I am trying to label different data in a figure and use the standard definition label='test'
!
ax = df.plot(style=['tab:blue'],linewidth=1.0, label ='test')
dfh.plot(ax=ax, style=['tab:orange'], linewidth=1.0, label="line1")
leg =plt.legend()
plt.show()
But as you can see this does not work!
what am I doing wrong?
CodePudding user response:
fig, axes = plt.subplots(1, 1)
axes.plot(df, style=['tab:blue'], linewidth=1.0, label='test')
axes.plot(dfh, style=['tab:orange'], linewidth=1.0, label='line1')
axes.legend()
CodePudding user response:
As per the matplotlib.pyplot.legend docs (https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.legend.html)
ax.plot([1, 2, 3], label='Inline label')
ax.legend()
Your code should be:
ax.plot(df, style=['tab:blue'],linewidth=1.0, label ='test')
ax.plot(dfh, style=['tab:orange'], linewidth=1.0, label="line1")
ax.legend()
plt.show()