1
我想將圖例添加到我的圖中,但不顯示。在下面的代碼中,「forecast_canvas」是在Qt Designer中創建的類Canvas的一個實例。無法在圖中添加圖例
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()
這裏是我的畫布的代碼:
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
import matplotlib.pyplot as plt from 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()
我嘗試添加
plt.legend()