我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用matplotlib.pylab.axvline()。
def plot_prediction_gp(params_fname, fig_fname, M=20): # load dataset data = np.loadtxt('./sandbox/hh_data.txt') # use the voltage and potasisum current data = data / np.std(data, axis=0) y = data[:, :4] xc = data[:, [-1]] # init hypers Dlatent = 2 Dobs = y.shape[1] T = y.shape[0] x_control = xc # x_control_test = np.flipud(x_control) x_control_test = x_control * 1.5 no_panes = 5 model_aep = aep.SGPSSM_GP(y, Dlatent, M, lik='Gaussian', prior_mean=0, prior_var=1000, x_control=x_control) model_aep.load_model(params_fname) print 'ls ', np.exp(model_aep.dyn_layer.ls) my, vy, vyn = model_aep.get_posterior_y() mxp, vxp, myp, vyp, vynp = model_aep.predict_forward(T, x_control_test) cs = ['k', 'r', 'b', 'g'] labels = ['V', 'm', 'n', 'h'] plt.figure() t = np.arange(T) for i in range(4): yi = y[:, i] mi = my[:, i] vi = vy[:, i] vin = vyn[:, i] mip = myp[:, i] vip = vyp[:, i] vinp = vynp[:, i] plt.subplot(5, 1, i + 1) plt.fill_between(t, mi + 2 * np.sqrt(vi), mi - 2 * np.sqrt(vi), color=cs[i], alpha=0.4) plt.plot(t, mi, '-', color=cs[i]) plt.fill_between(np.arange(T, 2 * T), mip + 2 * np.sqrt(vip), mip - 2 * np.sqrt(vip), color=cs[i], alpha=0.4) plt.plot(np.arange(T, 2 * T), mip, '-', color=cs[i]) plt.plot(t, yi, '--', color=cs[i]) plt.axvline(x=T, color='k', linewidth=2) plt.ylabel(labels[i]) plt.xticks([]) plt.yticks([]) plt.subplot(no_panes, 1, no_panes) plt.plot(t, x_control, '-', color='m') plt.plot(np.arange(T, 2 * T), x_control_test, '-', color='m') plt.axvline(x=T, color='k', linewidth=2) plt.ylabel('I') plt.yticks([]) plt.xlabel('t') plt.savefig(fig_fname)
def plotPolicy(self, policy, prefix): plt.clf() for idx in xrange(len(policy)): i, j = self.env.getStateXY(idx) dx = 0 dy = 0 if policy[idx] == 0: # up dy = 0.35 elif policy[idx] == 1: #right dx = 0.35 elif policy[idx] == 2: #down dy = -0.35 elif policy[idx] == 3: #left dx = -0.35 elif self.matrixMDP[i][j] != -1 and policy[idx] == 4: # termination circle = plt.Circle( (j + 0.5, self.numRows - i + 0.5 - 1), 0.025, color='k') plt.gca().add_artist(circle) if self.matrixMDP[i][j] != -1: plt.arrow(j + 0.5, self.numRows - i + 0.5 - 1, dx, dy, head_width=0.05, head_length=0.05, fc='k', ec='k') else: plt.gca().add_patch( patches.Rectangle( (j, self.numRows - i - 1), # (x,y) 1.0, # width 1.0, # height facecolor = "gray" ) ) plt.xlim([0, self.numCols]) plt.ylim([0, self.numRows]) for i in xrange(self.numCols): plt.axvline(i, color='k', linestyle=':') plt.axvline(self.numCols, color='k', linestyle=':') for j in xrange(self.numRows): plt.axhline(j, color='k', linestyle=':') plt.axhline(self.numRows, color='k', linestyle=':') plt.savefig(self.outputPath + prefix + 'policy.png') plt.close()