def showDomain(self, a): s = self.state # Plot the car x, y, speed, heading = s car_xmin = x - self.REAR_WHEEL_RELATIVE_LOC car_ymin = y - self.CAR_WIDTH / 2. if self.domain_fig is None: # Need to initialize the figure self.domain_fig = plt.figure() # Goal plt.gca().add_patch( plt.Circle(self.GOAL, radius=self.GOAL_RADIUS, color='g', alpha=.4)) plt.xlim([self.XMIN, self.XMAX]) plt.ylim([self.YMIN, self.YMAX]) plt.gca().set_aspect('1') # Car if self.car_fig is not None: plt.gca().patches.remove(self.car_fig) self.car_fig = mpatches.Rectangle([car_xmin, car_ymin], self.CAR_LENGTH, self.CAR_WIDTH, alpha=.4) rotation = mpl.transforms.Affine2D().rotate_deg_around( x, y, heading * 180 / np.pi) + plt.gca().transData self.car_fig.set_transform(rotation) plt.gca().add_patch(self.car_fig) plt.draw()
def showStateDistribution(self, all_state_list, colors): ## HACKY - WILL NEED TO CLEAN UP if self.gcf is None: self.gcf = plt.gcf() plt.gca().add_patch( plt.Circle(self.GOAL, radius=self.GOAL_RADIUS, color='g', alpha=.4)) plt.xlim([self.XMIN, self.XMAX]) plt.ylim([self.YMIN, self.YMAX]) plt.gca().set_aspect('1') for state_list, color in zip(all_state_list, colors): for state in state_list: plt.gca().add_patch( plt.Circle(state[:2], radius=0.01, color=color, alpha=.4)) plt.draw() self.gcf.canvas.draw()
def showDomain(self, a): if self.gcf is None: self.gcf = plt.gcf() s = self.state # Plot the car x, y, speed, heading = s car_xmin = x - self.REAR_WHEEL_RELATIVE_LOC car_ymin = y - self.CAR_WIDTH / 2. if self.domain_fig is None: # Need to initialize the figure self.domain_fig = plt.figure() # Goal plt.gca( ).add_patch( plt.Circle( self.GOAL, radius=self.GOAL_RADIUS, color='g', alpha=.4)) plt.xlim([self.XMIN, self.XMAX]) plt.ylim([self.YMIN, self.YMAX]) plt.gca().set_aspect('1') # Car if self.car_fig is not None: plt.gca().patches.remove(self.car_fig) if self.slips: slip_x, slip_y = zip(*self.slips) try: line = plt.axes().lines[0] if len(line.get_xdata()) != len(slip_x): # if plot has discrepancy from data line.set_xdata(slip_x) line.set_ydata(slip_y) except IndexError: plt.plot(slip_x, slip_y, 'x', color='b') self.car_fig = mpatches.Rectangle( [car_xmin, car_ymin], self.CAR_LENGTH, self.CAR_WIDTH, alpha=.4) rotation = mpl.transforms.Affine2D().rotate_deg_around( x, y, heading * 180 / np.pi) + plt.gca().transData self.car_fig.set_transform(rotation) plt.gca().add_patch(self.car_fig) plt.draw() # self.gcf.canvas.draw() plt.pause(0.001)