def _plot_valfun(self, VMat, xlim=None, ylim=None): """ :returns: handle to the figure """ plt.figure("Value Function") # pl.xticks(self.xTicks,self.xTicksLabels, fontsize=12) # pl.yticks(self.yTicks,self.yTicksLabels, fontsize=12) # pl.xlabel(r"$\theta$ (degree)") # pl.ylabel(r"$\dot{\theta}$ (degree/sec)") plt.title("Value Function") if xlim is not None and ylim is not None: extent = [xlim[0], xlim[1], ylim[0], ylim[1]] else: extent = [0, 1, 0, 1] self.valueFunction_fig = plt.imshow( VMat, cmap="ValueFunction", interpolation="nearest", origin="lower", extent=extent, ) norm = colors.Normalize(vmin=VMat.min(), vmax=VMat.max()) self.valueFunction_fig.set_data(VMat) self.valueFunction_fig.set_norm(norm) plt.draw()
def show_domain(self, a=0): s = self.state # Draw the environment if self.domain_fig is None: self.move_fig = plt.subplot(111) s = s.reshape((self.BOARD_SIZE, self.BOARD_SIZE)) self.domain_fig = plt.imshow(s, cmap="FlipBoard", interpolation="nearest", vmin=0, vmax=1) plt.xticks(np.arange(self.BOARD_SIZE), fontsize=FONTSIZE) plt.yticks(np.arange(self.BOARD_SIZE), fontsize=FONTSIZE) # pl.tight_layout() a_row, a_col = id2vec(a, [self.BOARD_SIZE, self.BOARD_SIZE]) self.move_fig = self.move_fig.plot(a_col, a_row, "kx", markersize=30.0) plt.show() a_row, a_col = id2vec(a, [self.BOARD_SIZE, self.BOARD_SIZE]) self.move_fig.pop(0).remove() # print a_row,a_col # Instead of '>' you can use 'D', 'o' self.move_fig = plt.plot(a_col, a_row, "kx", markersize=30.0) s = s.reshape((self.BOARD_SIZE, self.BOARD_SIZE)) self.domain_fig.set_data(s) plt.draw()
def show_domain(self, a=0): # Draw the environment s = self.state world = np.zeros((self.blocks, self.blocks), "uint8") undrawn_blocks = np.arange(self.blocks) while len(undrawn_blocks): A = undrawn_blocks[0] B = s[A] undrawn_blocks = undrawn_blocks[1:] if B == A: # => A is on Table world[0, A] = A + 1 # 0 is white thats why! else: # See if B is already drawn i, j = findElemArray2D(B + 1, world) if len(i): world[i + 1, j] = A + 1 # 0 is white thats why! else: # Put it in the back of the list undrawn_blocks = np.hstack((undrawn_blocks, [A])) if self.domain_fig is None: plt.figure("Domain") self.domain_fig = plt.imshow( world, cmap="BlocksWorld", origin="lower", interpolation="nearest") # ,vmin=0,vmax=self.blocks) plt.xticks(np.arange(self.blocks), fontsize=FONTSIZE) plt.yticks(np.arange(self.blocks), fontsize=FONTSIZE) # pl.tight_layout() plt.axis("off") plt.show() else: self.domain_fig.set_data(world) plt.figure("Domain").canvas.draw() plt.figure("Domain").canvas.flush_events()
def _plot_policy(self, piMat, title="Policy", var="policy_fig", xlim=None, ylim=None): """ :returns: handle to the figure """ if getattr(self, var, None) is None: plt.figure(title) # define the colormap cmap = plt.cm.jet # extract all colors from the .jet map cmaplist = [cmap(i) for i in range(cmap.N)] # force the first color entry to be grey cmaplist[0] = (0.5, 0.5, 0.5, 1.0) # create the new map cmap = cmap.from_list("Custom cmap", cmaplist, cmap.N) # define the bins and normalize bounds = np.linspace(0, self.num_actions, self.num_actions + 1) norm = mpl.colors.BoundaryNorm(bounds, cmap.N) if xlim is not None and ylim is not None: extent = [xlim[0], xlim[1], ylim[0], ylim[1]] else: extent = [0, 1, 0, 1] self.__dict__[var] = plt.imshow( piMat, interpolation="nearest", origin="lower", cmap=cmap, norm=norm, extent=extent, ) # pl.xticks(self.xTicks,self.xTicksLabels, fontsize=12) # pl.yticks(self.yTicks,self.yTicksLabels, fontsize=12) # pl.xlabel(r"$\theta$ (degree)") # pl.ylabel(r"$\dot{\theta}$ (degree/sec)") plt.title(title) plt.colorbar() plt.figure(title) self.__dict__[var].set_data(piMat) plt.draw()
def show_domain(self, a): s = self.state # Draw the environment fig = plt.figure("IntruderMonitoring") if self.domain_fig is None: self.domain_fig = plt.imshow( self.map, cmap="IntruderMonitoring", interpolation="nearest", vmin=0, vmax=3, ) plt.xticks(np.arange(self.COLS), fontsize=FONTSIZE) plt.yticks(np.arange(self.ROWS), fontsize=FONTSIZE) plt.show() if self.ally_fig is not None: self.ally_fig.pop(0).remove() self.intruder_fig.pop(0).remove() s_ally = s[0:self.NUMBER_OF_AGENTS * 2].reshape((-1, 2)) s_intruder = s[self.NUMBER_OF_AGENTS * 2:].reshape((-1, 2)) self.ally_fig = plt.plot( s_ally[:, 1], s_ally[:, 0], "bo", markersize=30.0, alpha=0.7, markeredgecolor="k", markeredgewidth=2, ) self.intruder_fig = plt.plot( s_intruder[:, 1], s_intruder[:, 0], "g>", color="gray", markersize=30.0, alpha=0.7, markeredgecolor="k", markeredgewidth=2, ) fig.canvas.draw() fig.canvas.flush_events()