def __init__(self, parent=None, width=5, height=4, dpi=80):
self.fig = Figure(figsize=(width, height), dpi=dpi, facecolor='white')
FigureCanvas.__init__(self, self.fig)
self.setParent(parent)
# Create graphs and lines
self.graph_power = self.fig.add_subplot(211)
self.graph_error = self.fig.add_subplot(212)
zero = dt.datetime.fromtimestamp(0)
one = dt.datetime.fromtimestamp(1)
x, y = [zero, one], [0, 0]
self.predict_line, = self.graph_power.plot(x, y, color='k', linewidth=2)
self.target_line, = self.graph_power.plot(x, y, color='b', linestyle='--', linewidth=2)
self.error_line, = self.graph_error.plot(x, y, color='r')
self.color_spans = []
# Change settings of graph
self.graph_power.set_ylabel("Power (kW)")
self.graph_error.set_ylabel("Error (kW)")
self.graph_power.xaxis.set_major_formatter(DateFormatter("%Y-%m-%d %H:%M:%S"))
self.graph_error.xaxis.set_major_formatter(DateFormatter("%Y-%m-%d %H:%M:%S"))
self.graph_power.xaxis.set_major_locator(LinearLocator(numticks=7))
self.graph_error.xaxis.set_major_locator(LinearLocator(numticks=7))
# Add legend
self.graph_power.legend([self.target_line, self.predict_line], ['Actual Value', 'Predicted Value'])
#self.graph_error.legend([self.error_line], ['Error Value'])
# Rotate dates slightly
plt.setp(self.graph_power.get_xticklabels(), rotation=10)
plt.setp(self.graph_error.get_xticklabels(), rotation=10)
# Let graph expand with window
self.setSizePolicy(QtGui.QSizePolicy.Expanding,
QtGui.QSizePolicy.Expanding)
self.updateGeometry()
self.fig.tight_layout()
self.draw()
# Update the graph using the given data
# 'times' should be datetime objects
# 'target' should be float values in Watts
# 'predict' should be float values in Watts
评论列表
文章目录