python - Can't add legend in figure -
i want add legend figure, doesn't show. in code below "forecast_canvas" instance of class canvas created in qt designer.
ax = self.forecast_canvas.figure.add_subplot(111) ax.plot(self.new,'--',label='observed') ax.plot(data,color='green',label='forecast') self.forecast_canvas.draw()
here's code of canvas :
from matplotlib.backends.backend_qt4agg import figurecanvasqtagg figurecanvas import matplotlib.pyplot plt pyqt4 import qtgui class canvas(figurecanvas): def __init__(self, parent=none): self.figure = plt.figure() #plt.tight_layout(pad=4) figurecanvas.__init__(self, self.figure) self.setparent(parent) figurecanvas.setsizepolicy(self, qtgui.qsizepolicy.expanding, qtgui.qsizepolicy.expanding) figurecanvas.updategeometry(self) #plt.legend() i tried adding
plt.legend()
i think have 2 issues here:
- you need add legend after creating plots.
you may not able use
pyplot(plt.legend()) because pyplot may not host figures. (i'm saying "may" here, because don't know full code)
in case it's safer draw legend particular axes; in case useax.legend()

Comments
Post a Comment