def plot(self, ax=None, fill=False, source_id=None, **kwargs): import matplotlib.pyplot as plt import matplotlib.patches as mpatches kwargs['fill'] = fill if ax is None: ax = plt.gca() if source_id is None: positions = self.positions else: positions = self.positions[np.atleast_1d(source_id)] resolution = 20 for position in positions: patch_inner = mpatches.CirclePolygon(position, self.r_in, resolution=resolution) patch_outer = mpatches.CirclePolygon(position, self.r_out, resolution=resolution) path = _make_annulus_path(patch_inner, patch_outer) patch = mpatches.PathPatch(path, **kwargs) ax.add_patch(patch)
def drawRotors(self,z,h,theta): # Left Rotor lr_x = z-(P.d+self.VTOL['r'])*np.cos(theta) # x coordinate lr_y = h-(P.d+self.VTOL['r'])*np.sin(theta) # y coordinate lr_xy = (lr_x,lr_y) # Center of circle # Right Rotor rr_x = z+(P.d+self.VTOL['r'])*np.cos(theta) # x coordinate rr_y = h+(P.d+self.VTOL['r'])*np.sin(theta) # y coordinate rr_xy = (rr_x,rr_y) # Center of circle # When the class is initialized, a CirclePolygon patch object will # be created and added to the axes. After initialization, the # CirclePolygon patch object will only be updated. if self.flagInit == True: # Create the CirclePolygon patch and append its handle # to the handle list self.handle.append(mpatches.CirclePolygon(lr_xy, radius = self.VTOL['r'], resolution = 15, fc = 'none', ec = 'black')) self.ax.add_patch(self.handle[1]) # Add the patch to the axes self.handle.append(mpatches.CirclePolygon(rr_xy, radius = self.VTOL['r'], resolution = 15, fc = 'none', ec = 'black')) self.ax.add_patch(self.handle[2]) # Add the patch to the axes else: self.handle[1]._xy=lr_xy self.handle[2]._xy=rr_xy
def create_plan(self): out_radius = 7 if self.plan_choose == 0: in_radius = 0 elif self.plan_choose == 1: out_radius = 8 in_radius = 7 else: raise ValueError('0: Dense circle, 1: Sparse circle') plan = np.zeros((self.environment_height, self.environment_width)) a = np.array([12.5, 12.5]) circle = patches.CirclePolygon(a, out_radius) circle2 = patches.CirclePolygon(a, in_radius) for i in range(len(plan)): for j in range(len(plan[0])): a = np.array([i, j]) if circle.contains_point(a) and not circle2.contains_point(a): plan[i][j] = 1 total_area = sum(sum(plan)) area = sum(sum(plan)) return plan, area
def plotresult(filteredparticles, rejectedparticles, finalparticles, start, stop, stub, timestep, distancecutoff): """Plot the coordinates of identifed particles over the raw images they were obtained from.""" plotraw = True plotfilteredparticles = True plotrejectedparticles = True plotselected = True plot, ax = plt.subplots(figsize=(16, 20)) if plotraw: im = mpimg.imread(stub + "t" + '{:04d}'.format(timestep) + "_z" + '{:04d}'.format(start) + ".png") for image in range(start + 1, stop + 1): im = im + mpimg.imread(stub + "t" + '{:04d}'.format(timestep) + "_z" + '{:04d}'.format(image) + ".png") im = im / (stop - start + 1) plt.imshow(im) if plotfilteredparticles: patches = [] for particle in range(filteredparticles.shape[0]): patches.append( mpatches.CirclePolygon( (filteredparticles[particle, 0], filteredparticles[particle, 1]), radius=5)) p1 = PatchCollection(patches, alpha=0.2, color="blue") ax.add_collection(p1) if plotrejectedparticles: patches = [] for particle in range(rejectedparticles.shape[0]): patches.append( mpatches.CirclePolygon( (rejectedparticles[particle, 0], rejectedparticles[particle, 1]), radius=5)) p1 = PatchCollection(patches, alpha=0.2, color="green") ax.add_collection(p1) if plotselected: patches = [] for particle in range(finalparticles.shape[0]): patches.append( mpatches.CirclePolygon( (finalparticles[particle, 0], finalparticles[particle, 1]), radius=1)) p2 = PatchCollection(patches, alpha=1, color="red") ax.add_collection(p2) plt.xlim(0, 400) plt.ylim(0, 500) plt.savefig("t" + str(timestep) + "dist" + str(distancecutoff) + str(plotraw) + str(plotfilteredparticles) + str(plotrejectedparticles) + str(plotselected) + ".png")
def patchify_points(geoms, ec='black', fc='black', radius=0.1, *args, **kwargs): """Creates points patches from a sequence of geometries. Radius should be set accordingly to final picture extent. Default style can be modified using same kwargs as matplotlib.patches.CirclePolygon""" patches = [] for point in _point_iterator(geoms): if point.is_empty: continue # Monkey patching to easily add some basic styling kwargs_ = kwargs_from_prop(point, CIRCLEPOLY_PROPS, ['ec', 'fc', 'radius']) kwargs_.update(kwargs) ec = getattr(point, 'ec', ec) fc = getattr(point, 'fc', fc) radius = getattr(point, 'radius', radius) xy = point.coords patch = mpatches.CirclePolygon(*args, xy=tuple(xy)[0], radius=radius, ec=ec, fc=fc, **kwargs_) patches.append(patch) return patches
def plot(alpha, b, w): x0 = [] y0 = [] x1 = [] y1 = [] for i in range(0, len(Data)): if Data[i][1][0] == -1: x0.append(Data[i][0][0]) y0.append(Data[i][0][1]) else: x1.append(Data[i][0][0]) y1.append(Data[i][0][1]) plot = pyplot.figure() ax = plot.add_subplot(1, 1, 1) ax.scatter(x0, y0, marker='o', s=30, c='orange') ax.scatter(x1, y1, marker='o', s=30, c='green') for i in range(len(xArray)): if alpha[i] > 0.0 and alpha[i] != C: ax.add_patch( patches.CirclePolygon((xArray[i][0], xArray[i][0]), 0.25, facecolor='none', edgecolor=(0, 0, 0), linewidth=1, alpha=0.9)) x = np.arange(-5.0, 20.0, 0.1) y = (-w[0] * x - b) / w[1] ax.plot(x, y) ax.axis([-5, 10, -5, 10]) pyplot.show()
def plot(self, origin=(0, 0), indices=None, ax=None, fill=False, **kwargs): import matplotlib.patches as mpatches plot_positions, ax, kwargs = self._prepare_plot( origin, indices, ax, fill, **kwargs) resolution = 20 for position in plot_positions: patch_inner = mpatches.CirclePolygon(position, self.r_in, resolution=resolution) patch_outer = mpatches.CirclePolygon(position, self.r_out, resolution=resolution) path = self._make_annulus_path(patch_inner, patch_outer) patch = mpatches.PathPatch(path, **kwargs) ax.add_patch(patch)
def show_disk(file): with open(file) as f: lines = f.readlines()[2:] x = np.zeros(len(lines)) y = np.zeros_like(x) for i, line in enumerate(lines): s = line.replace("\n", "").split("\t") x[i] = float(s[1]) y[i] = float(s[2]) ax = plt.subplot(111) if x.size <= 10000: if x.size <= 5000: aa = True else: aa = False for i in range(x.size): ax.add_patch(patches.Circle((x[i], y[i]), 1, aa=aa)) else: for i in range(x.size): ax.add_patch( patches.CirclePolygon( (x[i], y[i]), 1, resolution=10, aa=False)) ax.axis("equal") plt.show() plt.close()
def drawVehicle(self, state, color="limegreen"): x_pos = state[0] y_pos = state[1] theta = state[2] radius = 0.5 xy = (x_pos, y_pos) X = [x_pos, x_pos + np.cos(theta)] Y = [y_pos, y_pos + np.sin(theta)] if self.flagInit == True: self.handle.append( mpatches.CirclePolygon(xy, radius=radius, resolution=15, fc=color, ec='black')) self.ax.add_patch(self.handle[0]) line, = self.ax.plot(X, Y, lw=1, c='red') self.handle.append(line) else: self.handle[0]._xy = xy self.handle[1].set_xdata(X) self.handle[1].set_ydata(Y)
def annotation2pltpatch(annotation, **kwargs): """ Convert geometric annotation to matplotlib geometric objects (=patches) For details regarding matplotlib patches see: http://matplotlib.org/api/patches_api.html For annotation formats see: imageutil.annotation2coords :param annotation annotation: Annotation of an image region such as point, circle, rect or polyline :return: matplotlib.patches :rtype: generator over matplotlib patches """ if not annotation or isnan(annotation): return kind, geometries = annotation for geo in geometries: if kind == 'point': pltpatch = plp.CirclePolygon((geo[0], geo[1]), 1, **kwargs) elif kind == 'circle': pltpatch = plp.Circle((geo[0], geo[1]), geo[2], **kwargs) elif kind == 'rect': x, y, w, h = geo pltpatch = plp.Rectangle((x, y), w, h, **kwargs) elif kind == 'polyline': pltpatch = plp.Polygon(geo, closed=False, **kwargs) else: raise ValueError('Invalid kind of annotation: ' + kind) yield pltpatch
def transit(self, planet, time, dt): I = [] D = [] Time = [] planetPoly = patches.CirclePolygon((0, 0), 1, 100) while (planet.isTransiting(time)): # Carry on now integrating planet across surface but don't rotate star planetFlux = self.unspottedFlux * np.ones( self.unspottedFlux.shape ) if self.spottedFlux is None else self.spottedFlux * np.ones( self.spottedFlux.shape) # Find position of planet and scale to star's radius X, Y = planet.skyPosAtTime(time) planet_vx = self.radius * ( planetPoly.get_path().vertices[:, 0] * planet.rad + X) planet_vy = self.radius * ( planetPoly.get_path().vertices[:, 1] * planet.rad + Y) planet_path = path.Path(np.column_stack((planet_vx, planet_vy))) # Find pixles contained within planet's disk and set to 0 mask = self.maskPixels(planet_path) planetFlux[mask] = 0 totalTransitFlux = self.totalFlux(planetFlux) I.append(totalTransitFlux) if self.spots is None: D.append(self.totalUnspottedFlux - totalTransitFlux) else: D.append(self.totalSpottedFlux - totalTransitFlux) Time.append(time) time += dt return I, D, Time, time
def plot(w, alpha, b): x0=[]; y0=[]; x1=[]; y1=[] for i in range(1, len(Tire_Depth)): if (Tire_Depth[i][1][0] == 1): x0.append(Tire_Depth[i][0][0]) y0.append(Tire_Depth[i][0][1]) else: x1.append(Tire_Depth[i][0][0]) y1.append(Tire_Depth[i][0][1]) plot = plt.figure() plt.xlabel(Tire_Depth[0][0][0]) plt.ylabel(Tire_Depth[0][0][1]) ax = plot.add_subplot(1,1,1) ax.scatter(x0, y0, marker = 'o', s = 25, c = 'red') ax.scatter(x1, y1, marker = 'o', s = 25, c = 'blue') for i in range(len(xR)): if alpha[i] != c and alpha[i] > 0: ax.add_patch(ps.CirclePolygon((xR[i][0], xR[i][1]), .2, facecolor='none', edgecolor=(0,0,0), linewidth=1, alpha=.9)) x = np.arange(0, 10, .1) y = (-w[0] * x - b) / w[1] ax.axis([0, 10, 0, 10]) ax.plot(x,y) plt.show()
def test_patch_str(): """ Check that patches have nice and working `str` representation. Note that the logic is that `__str__` is defined such that: str(eval(str(p))) == str(p) """ p = mpatches.Circle(xy=(1, 2), radius=3) assert str(p) == 'Circle(xy=(1, 2), radius=3)' p = mpatches.Ellipse(xy=(1, 2), width=3, height=4, angle=5) assert str(p) == 'Ellipse(xy=(1, 2), width=3, height=4, angle=5)' p = mpatches.Rectangle(xy=(1, 2), width=3, height=4, angle=5) assert str(p) == 'Rectangle(xy=(1, 2), width=3, height=4, angle=5)' p = mpatches.Wedge(center=(1, 2), r=3, theta1=4, theta2=5, width=6) assert str(p) == 'Wedge(center=(1, 2), r=3, theta1=4, theta2=5, width=6)' p = mpatches.Arc(xy=(1, 2), width=3, height=4, angle=5, theta1=6, theta2=7) expected = 'Arc(xy=(1, 2), width=3, height=4, angle=5, theta1=6, theta2=7)' assert str(p) == expected p = mpatches.Annulus(xy=(1, 2), r=(3, 4), width=1, angle=2) expected = "Annulus(xy=(1, 2), r=(3, 4), width=1, angle=2)" assert str(p) == expected p = mpatches.RegularPolygon((1, 2), 20, radius=5) assert str(p) == "RegularPolygon((1, 2), 20, radius=5, orientation=0)" p = mpatches.CirclePolygon(xy=(1, 2), radius=5, resolution=20) assert str(p) == "CirclePolygon((1, 2), radius=5, resolution=20)" p = mpatches.FancyBboxPatch((1, 2), width=3, height=4) assert str(p) == "FancyBboxPatch((1, 2), width=3, height=4)" # Further nice __str__ which cannot be `eval`uated: path = mpath.Path([(1, 2), (2, 2), (1, 2)], closed=True) p = mpatches.PathPatch(path) assert str(p) == "PathPatch3((1, 2) ...)" p = mpatches.Polygon(np.empty((0, 2))) assert str(p) == "Polygon0()" data = [[1, 2], [2, 2], [1, 2]] p = mpatches.Polygon(data) assert str(p) == "Polygon3((1, 2) ...)" p = mpatches.FancyArrowPatch(path=path) assert str(p)[:27] == "FancyArrowPatch(Path(array(" p = mpatches.FancyArrowPatch((1, 2), (3, 4)) assert str(p) == "FancyArrowPatch((1, 2)->(3, 4))" p = mpatches.ConnectionPatch((1, 2), (3, 4), 'data') assert str(p) == "ConnectionPatch((1, 2), (3, 4))" s = mpatches.Shadow(p, 1, 1) assert str(s) == "Shadow(ConnectionPatch((1, 2), (3, 4)))"
def drawLowerBall(self, x, y): if self.flagInit == True: self.handle.append( patches.CirclePolygon((x, y), radius=P.r, fc='gray', ec='gray')) self.ax.add_patch(self.handle[3]) else: self.handle[3]._xy = (x, y)
def drawCar(self, state): theta = state[2] xy = state[0:2] if self.flagInit: self.handle.append(patches.CirclePolygon(xy,radius = .5, resolution = 15, fc = 'limegreen', ec = 'black')) self.ax.add_patch(self.handle[0]) else: self.handle[0]._xy = xy
def test_patch_str(): """ Check that patches have nice and working `str` representation. Note that the logic is that `__str__` is defined such that: str(eval(str(p))) == str(p) """ p = mpatches.Circle(xy=(1, 2), radius=3) assert str(p) == 'Circle(xy=(1, 2), radius=3)' p = mpatches.Ellipse(xy=(1, 2), width=3, height=4, angle=5) assert str(p) == 'Ellipse(xy=(1, 2), width=3, height=4, angle=5)' p = mpatches.Rectangle(xy=(1, 2), width=3, height=4, angle=5) assert str(p) == 'Rectangle(xy=(1, 2), width=3, height=4, angle=5)' p = mpatches.Wedge(center=(1, 2), r=3, theta1=4, theta2=5, width=6) assert str(p) == 'Wedge(center=(1, 2), r=3, theta1=4, theta2=5, width=6)' p = mpatches.Arc(xy=(1, 2), width=3, height=4, angle=5, theta1=6, theta2=7) expected = 'Arc(xy=(1, 2), width=3, height=4, angle=5, theta1=6, theta2=7)' assert str(p) == expected p = mpatches.RegularPolygon((1, 2), 20, radius=5) assert str(p) == "RegularPolygon((1, 2), 20, radius=5, orientation=0)" p = mpatches.CirclePolygon(xy=(1, 2), radius=5, resolution=20) assert str(p) == "CirclePolygon((1, 2), radius=5, resolution=20)" p = mpatches.FancyBboxPatch((1, 2), width=3, height=4) assert str(p) == "FancyBboxPatch((1, 2), width=3, height=4)" # Further nice __str__ which cannot be `eval`uated: path_data = [([1, 2], mpath.Path.MOVETO), ([2, 2], mpath.Path.LINETO), ([1, 2], mpath.Path.CLOSEPOLY)] p = mpatches.PathPatch(mpath.Path(*zip(*path_data))) assert str(p) == "PathPatch3((1, 2) ...)" data = [[1, 2], [2, 2], [1, 2]] p = mpatches.Polygon(data) assert str(p) == "Polygon3((1, 2) ...)" p = mpatches.FancyArrowPatch(path=mpath.Path(*zip(*path_data))) assert str(p)[:27] == "FancyArrowPatch(Path(array(" p = mpatches.FancyArrowPatch((1, 2), (3, 4)) assert str(p) == "FancyArrowPatch((1, 2)->(3, 4))" p = mpatches.ConnectionPatch((1, 2), (3, 4), 'data') assert str(p) == "ConnectionPatch((1, 2), (3, 4))" s = mpatches.Shadow(p, 1, 1) assert str(s) == "Shadow(ConnectionPatch((1, 2), (3, 4)))" with pytest.warns(MatplotlibDeprecationWarning): p = mpatches.YAArrow(plt.gcf(), (1, 0), (2, 1), width=0.1) assert str(p) == "YAArrow()"
def create_plot(): fig, ax = plt.subplots() ax.grid(color='lightgray') rcolor_1 = [0.7074445660822728, 0.10479000173471098, 0.6414668195780913] rcolor_2 = [0.22633933378197624, 0.7236195586385642, 0.5361006106618125] p = [ patches.Arrow(0.75, 0.75, 0.5, 0.5), patches.Circle((1, 2), 0.4), patches.RegularPolygon((1, 3), 5, 0.4), patches.Rectangle((1.6, 0.75), 0.8, 0.5), patches.CirclePolygon((2, 2), 0.4), patches.Polygon([[1.75, 3], [2, 3.25], [2.25, 3], [2, 2.75], [1.75, 3]]), patches.Wedge((3, 1), 0.4, 0, 270), patches.Ellipse((3, 2), 0.6, 0.4), patches.Arc((3, 3), 0.5, 0.5, 270, 90) ] for patch in p: patch.set_facecolor(rcolor_1) patch.set_edgecolor(rcolor_2) patch.set_alpha(0.5) patch.set_linewidth(2) ax.add_patch(patch) # add a static patch ax.add_patch( patches.Rectangle((0.3, 0.4), 0.4, 0.4, fc='yellow', ec='black', alpha=0.3, transform=ax.transAxes)) # add a patch with facecolor=None ax.add_patch( patches.Circle((4.0, 2.5), 0.4, facecolor='none', edgecolor='k')) # add a patch with edgecolor=None ax.add_patch( patches.Circle((4.0, 1.5), 0.4, facecolor='#9999FF', edgecolor='none', linewidth=2)) # make sure axes ratio is equal ax.set_xlim(0.5, 0.5 + 3. * 4. / 3.) ax.set_ylim(0.5, 3.5) ax.set_title("Various Patches", size=16) return fig
def drawUpperBall(self, x, y): if self.flagInit == True: self.handle.append( patches.CirclePolygon((x, y), radius=P.r, fc='white', ec='white')) self.ax.add_patch(self.handle[1]) else: self.handle[1]._xy = (x, y)
def test_alpha(): # We want an image which has a background color and an # alpha of 0.4. fig = plt.figure(figsize=[2, 1]) fig.set_facecolor((0, 1, 0.4)) fig.patch.set_alpha(0.4) import matplotlib.patches as mpatches fig.patches.append( mpatches.CirclePolygon([20, 20], radius=15, alpha=0.6, facecolor='red'))
def create_plot(): fig, ax = plt.subplots() ax.grid(color='lightgray') rcolor = lambda: np.random.random(3) p = [ patches.Arrow(0.75, 0.75, 0.5, 0.5), patches.Circle((1, 2), 0.4), patches.RegularPolygon((1, 3), 5, 0.4), patches.Rectangle((1.6, 0.75), 0.8, 0.5), patches.CirclePolygon((2, 2), 0.4), patches.Polygon([[1.75, 3], [2, 3.25], [2.25, 3], [2, 2.75], [1.75, 3]]), patches.Wedge((3, 1), 0.4, 0, 270), patches.Ellipse((3, 2), 0.6, 0.4), patches.Arc((3, 3), 0.5, 0.5, 270, 90) ] for patch in p: patch.set_facecolor(rcolor()) patch.set_edgecolor(rcolor()) patch.set_alpha(0.5) patch.set_linewidth(2) ax.add_patch(patch) # add a static patch ax.add_patch( patches.Rectangle((0.3, 0.4), 0.4, 0.4, fc='yellow', ec='black', alpha=0.3, transform=ax.transAxes)) # add a patch with facecolor=None ax.add_patch( patches.Circle((4.0, 2.5), 0.4, facecolor='none', edgecolor='k')) # add a patch with edgecolor=None ax.add_patch( patches.Circle((4.0, 1.5), 0.4, facecolor='#9999FF', edgecolor='none', linewidth=2)) # make sure axes ratio is equal ax.set_xlim(0.5, 0.5 + 3. * 4. / 3.) ax.set_ylim(0.5, 3.5) ax.set_title("Various Patches", size=16) return fig
def drawPerson(self): i = 0 for xy in P.z: art = patches.CirclePolygon(xy, radius=P.rp, fc=self.colors[np.mod( i, len(self.colors) - 1)], ec='black') self.ax.add_patch(art) i += 1
def drawVehicle(self, state, idx, color="limegreen"): x_pos, y_pos, theta = state radius = 2 xy = (x_pos,y_pos) if self.flagInit == True: self.handle.append(mpatches.CirclePolygon(xy, radius = radius, resolution = 15, fc = color, ec = 'black')) self.ax.add_patch(self.handle[idx]) else: self.handle[idx]._xy=xy
def create_plan(self): out_radius = 7 if self.plan_choose == 0: in_radius = 0 elif self.plan_choose == 1: out_radius = 8 in_radius = 7 plan = np.zeros((self.environment_height, self.environment_width)) a = np.array([12.5, 12.5]) circle = patches.CirclePolygon(a, out_radius) circle2 = patches.CirclePolygon(a, in_radius) for i in range(len(plan)): for j in range(len(plan[0])): a = np.array([i, j]) if circle.contains_point(a) and not circle2.contains_point(a): plan[i][j] = 1 total_area = sum(sum(plan)) plan = plan * self.z total_area = total_area * self.z return plan, total_area
def drawBall(self, z, theta): X = np.cos(theta) * z - np.sin(theta) * (self.diameter / 2) Y = np.sin(theta) * z + np.cos(theta) * (self.diameter / 2 + .005) xy = (X, Y) if self.flagInit == True: self.handle.append( mpatches.CirclePolygon(xy, radius=P.diameter / 2, ec='black', fc='red')) self.ax.add_patch(self.handle[1]) else: self.handle[1]._xy = xy
def drawPerson(self, z): xp = z[0] yp = z[1] xy = [xp, yp] if self.flag_init == True: art = patches.CirclePolygon(xy, radius=P.rp, fc='red', ec='black') self.handle.append(art) # self.handle.append(patches.Circle(xy, radius = P.rp, fc = 'blue', ec = 'black')) self.ax.add_patch(self.handle[1]) else: self.handle[1]._xy = xy self.ax.add_patch(self.handle[1])
def drawCircle(self, z, theta): x = z+(P.ell+P.radius)*np.sin(theta) # x coordinate y = (P.gap+P.h)-(P.ell+P.radius)*np.cos(theta) # y coordinate xy = (x,y) # Center of circle # When the class is initialized, a CirclePolygon patch object is # created and added to the axes. if self.flagInit == True: # Create the CirclePolygon patch and append its handle # to the handle list self.handle.append(mpatches.CirclePolygon(xy, radius = P.radius, resolution = 15, fc = 'limegreen', ec = 'black')) self.ax.add_patch(self.handle[1]) # Add the patch to the axes else: self.handle[1]._xy=xy
def drawCar(self, z): xc = z[0] yc = z[1] xy = (xc, yc) s = P.sc if self.flag_init == True: art = patches.CirclePolygon(xy, radius=P.sc, fc='blue', ec='black') self.handle.append(art) #The issue is with the rectangle patch. Not sure what is up with it # self.handle.append(patches.Rectangle(xy, s, s, fc = 'green', ec = 'black')) self.ax.add_patch(self.handle[0]) else: self.handle[0]._xy = xy self.ax.add_patch(self.handle[0])
def drawwing1(self, zv,h,theta): # specify center of circle x = zv+((P.radius+P.d)*(np.sin(theta))) y = h+((P.radius+P.d)*(np.cos(theta))) center = (x,y) # create circle on first call, update on subsequent calls if self.flag_init == True: # Create the CirclePolygon patch and append its handle # to the handle list self.handle.append( mpatches.CirclePolygon(center, radius=P.radius, resolution=15, fc='limegreen', ec='black')) # Add the patch to the axes self.ax.add_patch(self.handle[2]) else: self.handle[2]._xy = center
def drawBall(self, z, theta): x = z*np.cos(theta) - P.platform*np.sin(theta) y = z*np.sin(theta) + P.platform*np.cos(theta) xy = (x, y) # Center of circle # When the class is initialized, a CirclePolygon patch object will # be created and added to the axes. After initialization, the # CirclePolygon patch object will only be updated. if self.flagInit == True: # Create the CirclePolygon patch and append its handle # to the handle list self.handle.append(mpatches.CirclePolygon(xy, radius=P.radius, resolution=25, fc='orange', ec='black')) self.ax.add_patch(self.handle[0]) # Add the patch to the axes else: self.handle[0]._xy = xy
def draw_fov(self, target): rectangle_start_point = [ target[0] - cp.center_of_rect, target[1] - cp.center_of_rect ] if self.init_flag: self.rect = mpatches.Rectangle(rectangle_start_point, cp.fov_len, cp.fov_len, linewidth=1, edgecolor='r', facecolor='none') self.circle = mpatches.CirclePolygon(target, radius=15, color='r') self.ax.add_patch(self.circle) self.ax.add_patch(self.rect) else: self.rect.set_xy(rectangle_start_point) self.circle._xy = target