def subplotSingle2x(self, figNum, plotNum, numRows, numCols, time, data, title='', units='', options=''): print("subplotSingle2x") plt.figure(figNum) if title: self.title = title if not units: self.units = units if self.preTitle: fig = plt.gcf() fig.canvas.set_window_title("%s" % (figNum, self.preTitle)) if not figNum in self.sharex.keys(): self.sharex[figNum] = plt.subplot(numRows, numCols, plotNum) plt.plot(time, data, options) plt.subplot(numRows, numCols, plotNum, sharex=self.sharex[figNum]) # plt.hold(True); plt.grid(True) plt.title("%s" % (self.title)) plt.plot(time, data, options) plt.ylabel('(%s)' % (self.units)) plt.margins(0.04)
def plot2(self, figNum, time1, data1, time2, data2, title='', units='', options=''): plt.figure(figNum) # plt.hold(True); plt.grid(True) if title: self.title = title if not units: self.units = units # plt.cla() if self.preTitle: fig = plt.gcf() fig.canvas.set_window_title("Figure %d - %s" % (figNum, self.preTitle)) plt.title("%s" % (self.title)) plt.plot(time1, data1, options) plt.plot(time2, data2, options) plt.ylabel('(%s)' % (self.units)) plt.xlabel('Time (s)') plt.margins(0.04)
def draw_predictions(self, data, predictions): from pylab import plt true, lstm, bp = [], [], [] for i in range(len(predictions)): true.append(predictions[i][0]) bp.append(predictions[i][1]) lstm.append(predictions[i][2]) x = [1, 2, 3, 4, 5] plt.plot(x, true, 'cx--', label='true') plt.plot(x, bp, 'mo:', label='fusion') plt.plot(x, lstm, 'kp-.', label='lstm') plt.legend() plt.margins(0) plt.subplots_adjust(bottom=0.15) plt.xlabel(u"days") plt.ylabel("price") plt.title("tendency predictions of different models") plt.savefig('blog/static/blog/bootstrap/img/presult.jpg')
def plot3Axes(self, figNum, time, data, title='', units='', xlabel='Time (s)', options='', xlim=None, ylim=None): fig = plt.figure(figNum) # plt.cla() if title: self.title = title if units: self.units = units if self.preTitle: fig.canvas.set_window_title("Figure %d - %s" % (figNum, self.preTitle)) if not figNum in self.sharex.keys(): self.sharex[figNum] = plt.subplot(3, 1, 1) # plt.plot(time, data[:,0], options) # Plot 1 subplt = plt.subplot(3, 1, 1, sharex=self.sharex[figNum]) # plt.hold(True); plt.grid(True) plt.title("%s" % (self.title)) plt.ylabel('(%s)' % (self.units)) plt.xlabel(xlabel) plt.margins(0.04) if xlim: subplt.set_xlim(xlim) if ylim: subplt.set_ylim(ylim) if self.timeIsUtc: dates = [dt.datetime.fromtimestamp(ts) for ts in time] datenums = md.date2num(dates) # plt.subplots_adjust(bottom=0.2) plt.xticks(rotation=25) ax = plt.gca() if self.timeIsUtc == 2: xfmt = md.DateFormatter('%H:%M:%S.%f') else: xfmt = md.DateFormatter('%H:%M:%S') ax.xaxis.set_major_formatter(xfmt) plt.plot(datenums, data[:, 0], options) else: plt.plot(time, data[:, 0], options) # Plot 2 subplt = plt.subplot(3, 1, 2, sharex=self.sharex[figNum]) # plt.hold(True); plt.grid(True) plt.ylabel('(%s)' % (self.units)) plt.xlabel(xlabel) plt.margins(0.04) if xlim: subplt.set_xlim(xlim) if ylim: subplt.set_ylim(ylim) if self.timeIsUtc: dates = [dt.datetime.fromtimestamp(ts) for ts in time] datenums = md.date2num(dates) # plt.subplots_adjust(bottom=0.2) plt.xticks(rotation=25) ax = plt.gca() if self.timeIsUtc == 2: xfmt = md.DateFormatter('%H:%M:%S.%f') else: xfmt = md.DateFormatter('%H:%M:%S') ax.xaxis.set_major_formatter(xfmt) plt.plot(datenums, data[:, 1], options) else: plt.plot(time, data[:, 1], options) # Plot 3 subplt = plt.subplot(3, 1, 3, sharex=self.sharex[figNum]) # plt.hold(True); plt.grid(True) plt.ylabel('(%s)' % (self.units)) plt.xlabel(xlabel) plt.margins(0.04) if xlim: subplt.set_xlim(xlim) if ylim: subplt.set_ylim(ylim) if self.timeIsUtc: dates = [dt.datetime.fromtimestamp(ts) for ts in time] datenums = md.date2num(dates) # plt.subplots_adjust(bottom=0.2) plt.xticks(rotation=25) ax = plt.gca() if self.timeIsUtc == 2: xfmt = md.DateFormatter('%H:%M:%S.%f') else: xfmt = md.DateFormatter('%H:%M:%S') ax.xaxis.set_major_formatter(xfmt) plt.plot(datenums, data[:, 2], options) else: plt.plot(time, data[:, 2], options) # legend(['desire','actual','e/10','e2/10']) return fig