def __init__(self, outputPlot): self.decayValue = 0 self.outputPlot = outputPlot self.measurementPatch = Rectangle((0, 0), 1, 1, linewidth=1, color='gray', facecolor='none') self.statePatch = Circle((0, 0), 1, facecolor='blue') self.speedPatch = Arrow(0, 0, 3, 3) self.circlePatch = Circle((0, 0), 1, linewidth=1, color='red', facecolor='None') self.linePatch = ConnectionPatch((0, 0), (1, 1), 'data') self.model = 0 self.startLine = (0, 0) self.needToResetStartLine = True self.outputPlot.add_patch(self.measurementPatch) self.outputPlot.add_patch(self.statePatch) self.outputPlot.add_patch(self.speedPatch) self.outputPlot.add_patch(self.circlePatch) self.outputPlot.add_patch(self.linePatch) self.circlePatch.set_visible(False) self.linePatch.set_visible(False)
def update_car(self, pos_angle, inters): self.car.remove() self.head.remove() pos = tuple(pos_angle[:2]) angle = math.radians(pos_angle[2]) self.car = Circle(pos, radius=3, color='mediumblue') self.head = Arrow(pos[0], pos[1], dx=5 * math.cos(angle), dy=5 * math.sin(angle), facecolor='gold', edgecolor='k') if self.radars: for radar in self.radars: radar.remove() self.radars = [ Line2D(*zip(pos, inter), linestyle='-', color='gray') for inter in inters ] for radar in self.radars: self.ax.add_line(radar) self.ax.add_artist(self.car) self.ax.add_artist(self.head) self.draw()
def update(self): try: self.pupil_patch.remove() self.center_patch.remove() self.x_patch.remove() self.y_patch.remove() except AttributeError: pass except ValueError: pass if self.ind in self.pupil_list: self.pupil_at_ind = self.pupil_list[self.ind] if self.pupil_at_ind: self.pupil_circle = Circle((self.pupil_at_ind.center_col, self.pupil_at_ind.center_row), self.pupil_at_ind.radius, fill=False, ec=[1, 0, 0]) self.pupil_center = Circle((self.pupil_at_ind.center_col, self.pupil_at_ind.center_row), int(0.1 * self.pupil_at_ind.radius), fill=True, ec=[1, 0, 0], fc=[1, 0, 0]) self.pupil_patch = self.ax.add_patch(self.pupil_circle) self.center_patch = self.ax.add_patch(self.pupil_center) else: print('ERROR: No pupil at frame index %d' % (self.ind)) if self.ind in self.torsion_list: self.angle = self.torsion_list[self.ind] radius = self.video.height / 2 if self.pupil_at_ind: self.x_axis = Arrow( self.pupil_at_ind.center_col, self.pupil_at_ind.center_row, radius * np.cos(np.pi * (self.angle) / 180), -radius * np.sin(np.pi * (self.angle) / 180), width=5, ec=[1, 0, 0], fc=[1, 0, 0], fill=True) self.y_axis = Arrow( self.pupil_at_ind.center_col, self.pupil_at_ind.center_row, radius * np.cos(np.pi * (self.angle + 90) / 180), -radius * np.sin(np.pi * (self.angle + 90) / 180), width=5, ec=[1, 0, 0], fc=[1, 0, 0], fill=True) self.x_patch = self.ax.add_patch(self.x_axis) self.y_patch = self.ax.add_patch(self.y_axis) else: print('ERROR: No pupil at frame index %d' % (self.ind)) self.im.set_data(self.video[self.ind]) self.ax.set_xlabel('Frame %s' % self.ind) self.im.axes.figure.canvas.draw()
def createPlot(self, fig=None, ax=None): self.timeOfLastPlot = -1 if (fig is None): self.fig = plt.figure() else: self.fig = fig if (ax is None): self.ax = self.fig.add_subplot(111) else: self.ax = ax (verticesX, verticesY) = self.getDrawingVertex() self.bodyLine, = self.ax.plot(verticesX, verticesY, 'k') self.directionArrow = Arrow(self.x, self.y, 0.1 * self.v * cos(self.orientation), 0.1 * self.v * sin(self.orientation), color='c') self.ax.add_patch(self.directionArrow) self.ax.set_xlim([self.x - 10, self.x + 10]) self.ax.set_ylim([self.y - 10, self.y + 10]) self.ax.set_xlabel('Distance X') self.ax.set_ylabel('Distance Y')
def plot(self, draw=True): self.tractorFront.set_ydata(self.tractor.y) self.tractorFront.set_xdata(self.tractor.x) self.tractorLine.set_ydata([self.tractor.y, self.trailer.y]) self.tractorLine.set_xdata([self.tractor.x, self.trailer.x]) self.directionArrow.remove() self.directionArrow = Arrow( self.tractor.x, self.tractor.y, 0.1 * self.tractor.v * cos(self.tractor.orientation + self.tractor.phi), 0.1 * self.tractor.v * sin(self.tractor.orientation + self.tractor.phi), color='c') self.ax.add_patch(self.directionArrow) self.trailerFront.set_ydata(self.trailer.y) self.trailerFront.set_xdata(self.trailer.x) x_4 = self.trailer.x - (self.trailer.length + self.trailer.tailDistance ) * cos(self.trailer.orientation) y_4 = self.trailer.y - (self.trailer.length + self.trailer.tailDistance ) * sin(self.trailer.orientation) self.trailerLine.set_ydata([y_4, self.trailer.y]) self.trailerLine.set_xdata([x_4, self.trailer.x]) self.ax.set_xlim([self.trailer.x - 10, self.trailer.x + 10]) self.ax.set_ylim([self.trailer.y - 10, self.trailer.y + 10]) if (draw): self.fig.canvas.draw() plt.pause(0.001)
def draw_annotation(ax, locan, color, start, end): for c, an in enumerate(locan): rect = Rectangle((an[0], 0.25 + c), an[1] - an[0], 0.5, facecolor=color, edgecolor=color) l = min((end - start) / 20, an[1] - an[0]) if (an[3] == '+'): arrow = Arrow(an[1] - l, 0.5 + c, l, 0, width=.75, facecolor='black', edgecolor='black') else: arrow = Arrow(an[0] + l, 0.5 + c, -l, 0, width=.75, facecolor='black', edgecolor='black') ax.add_patch(rect) ax.add_patch(arrow)
def animate(n): function.set_data(outputarray.real[:n:2, -1], outputarray.imag[:n:2, -1]) for ii in range(i): arrows[ii].remove() for ii in range(i): if ii == 0: arrows[ii] = Arrow(0, 0, outputarray.real[n, 0], outputarray.imag[n, 1], color='k', lw=1) else: arrows[ii] = Arrow(outputarray.real[n, ii-1], outputarray.imag[n, ii-1], outputarray.real[n, ii], outputarray.imag[n, ii], color='k', lw=1) ax.add_patch(arrows[ii]) return function,
def triangle(lns, l_rad): patches = [] x_c, y_c = tr_center(l_rad) x_cent = np.mean(x_c) y_cent = np.mean(y_c) for x, y in zip(x_c, y_c): patches.append(Circle((x, y), l_rad)) patches.append( Arrow(x_cent, y_cent, x_c[lns] - x_cent, y_c[lns] - y_cent, width=0.2)) patches.append( Arrow(x_cent, y_cent, y_c[lns] - y_cent, x_cent - x_c[lns], width=0.2)) return PatchCollection(patches)
def plot_contour(self, w=0.0): """ Plot contour with poles of Green's function in the self-energy SelfEnergy(w) = G(w+w')W(w') with respect to w' = Re(w')+Im(w') Poles of G(w+w') are located: w+w'-(E_n-Fermi)+i*eps sign(E_n-Fermi)==0 ==> w'= (E_n-Fermi) - w -i eps sign(E_n-Fermi) """ try: import matplotlib.pyplot as plt from matplotlib.patches import Arc, Arrow except: print('no matplotlib?') return fig, ax = plt.subplots() fe = self.fermi_energy ee = self.mo_energy iee = 0.5 - np.array(ee > fe) eew = ee - fe - w ax.plot(eew, iee, 'r.', ms=10.0) pp = list() pp.append( Arc((0, 0), 4, 4, angle=0, linewidth=2, theta1=0, theta2=90, zorder=2, color='b')) pp.append( Arc((0, 0), 4, 4, angle=0, linewidth=2, theta1=180, theta2=270, zorder=2, color='b')) pp.append(Arrow(0, 2, 0, -4, width=0.2, color='b', hatch='o')) pp.append(Arrow(-2, 0, 4, 0, width=0.2, color='b', hatch='o')) for p in pp: ax.add_patch(p) ax.set_aspect('equal') ax.grid(True, which='both') ax.axhline(y=0, color='k') ax.axvline(x=0, color='k') plt.ylim(-3.0, 3.0) plt.show()
def createPlot(self, fig=None, ax=None): self.timeOfLastPlot = -1 if (fig is None): self.fig = plt.figure() else: self.fig = fig if (ax is None): self.ax = self.fig.add_subplot(111) else: self.ax = ax for b in self.bodies: (verticesX, verticesY) = b.getDrawingVertex() bodyLine, = self.ax.plot(verticesX, verticesY, 'k') self.bodyLines.append(bodyLine) directionArrow = Arrow(b.x, b.y, 0.1 * b.v * cos(b.orientation), 0.1 * b.v * sin(b.orientation), color='c') self.bodyArrows.append(directionArrow) self.ax.add_patch(directionArrow) (verticesX, verticesY) = self.centerBody.getDrawingVertex() self.centerBodyLine, = self.ax.plot(verticesX, verticesY, 'r') self.centerBodyArrow = Arrow( self.centerBody.x, self.centerBody.y, 0.1 * b.v * cos(self.centerBody.orientation), 0.1 * b.v * sin(self.centerBody.orientation), color='c') self.ax.add_patch(self.centerBodyArrow) self.radiusCircle = Circle((self.centerBody.x, self.centerBody.y), self.mapRadius, color='k', linestyle=':', fill=False) self.ax.add_patch(self.radiusCircle) self.ax.set_xlim([ self.centerBody.x - self.mapRadius * 1.1, self.centerBody.x + self.mapRadius * 1.1 ]) self.ax.set_ylim([ self.centerBody.y - self.mapRadius * 1.1, self.centerBody.y + self.mapRadius * 1.1 ]) self.ax.set_xlabel('Distance X') self.ax.set_ylabel('Distance Y')
def plot(self, draw=True): for idx in range(len(self.bodies)): b = self.bodies[idx] (verticesX, verticesY) = b.getDrawingVertex() bodyLine = self.bodyLines[idx] bodyLine.set_ydata(verticesY) bodyLine.set_xdata(verticesX) directionArrow = self.bodyArrows[idx] directionArrow.remove() directionArrow = Arrow(b.x, b.y, 0.1 * b.v * cos(b.orientation), 0.1 * b.v * sin(b.orientation), color='c') self.ax.add_patch(directionArrow) self.bodyArrows[idx] = directionArrow (verticesX, verticesY) = self.centerBody.getDrawingVertex() self.centerBodyLine.set_ydata(verticesY) self.centerBodyLine.set_xdata(verticesX) self.centerBodyArrow.remove() self.centerBodyArrow = Arrow( self.centerBody.x, self.centerBody.y, 0.1 * self.centerBody.v * cos(self.centerBody.orientation), 0.1 * self.centerBody.v * sin(self.centerBody.orientation), color='c') self.ax.add_patch(self.centerBodyArrow) self.radiusCircle.remove() self.radiusCircle = Circle((self.centerBody.x, self.centerBody.y), self.mapRadius, color='k', linestyle=':', fill=False) self.ax.add_patch(self.radiusCircle) self.ax.set_xlim([ self.centerBody.x - self.mapRadius * 1.1, self.centerBody.x + self.mapRadius * 1.1 ]) self.ax.set_ylim([ self.centerBody.y - self.mapRadius * 1.1, self.centerBody.y + self.mapRadius * 1.1 ]) if (draw): self.fig.canvas.draw() plt.pause(0.001)
def createPlot(self, fig=None, ax=None): self.timeOfLastPlot = -1 if (fig is None): self.fig = plt.figure() else: self.fig = fig if (ax is None): self.ax = self.fig.add_subplot(111) else: self.ax = ax self.tractorFront, = self.ax.plot(self.tractor.x, self.tractor.y, 'r*', label='Tractor Front') self.tractorLine, = self.ax.plot([self.tractor.x, self.trailer.x], [self.tractor.y, self.trailer.y], 'k', label='Tractor Body') self.trailerFront, = self.ax.plot(self.trailer.x, self.trailer.y, 'm*', label='Trailer Front') self.trailerLine, = self.ax.plot([ self.trailer.x, self.trailer.x - self.trailer.length * cos(self.trailer.length) ], [ self.trailer.y, self.trailer.y - self.trailer.length * sin(self.trailer.length) ], 'b', label='Trailer Body') self.directionArrow = Arrow( self.tractor.x, self.tractor.y, 0.1 * self.tractor.v * cos(self.tractor.orientation + self.tractor.phi), 0.1 * self.tractor.v * sin(self.tractor.orientation + self.tractor.phi), color='c', label='Wheel Direction') self.ax.add_patch(self.directionArrow) self.ax.set_xlim([-10, 10]) self.ax.set_ylim([-10, 10]) self.ax.set_xlabel('Distance X') self.ax.set_ylabel('Distance Y') self.ax.legend()
def changeEmitter(self): """ Emitter position changed button click event handler """ # ------------------------ Parsing new valus --------------------------- try: xAxis = float(self.emitterXLineEdit.text()) except Exception: print("changeEmitter(): x axis is in wrong format!") return try: yAxis = float(self.emitterYLineEdit.text()) except Exception: print("changeEmitter(): y axis is in wrong format!") return try: xVector = int(self.emitterXVectorLineEdit.text()) except Exception: print("changeEmitter(): x axis vector is in wrong format!") return try: yVector = int(self.emitterYVectorLineEdit.text()) except Exception: print("changeEmitter(): y axis vector is in wrong format!") return # ----------------------------------------------------------------------- # Changing emitter position self.emitter.change_position([xAxis, yAxis], [xVector, yVector]) # Removing old emitter (we have no emitter, don't do anything) try: self.emitter_vector.remove() except Exception: pass # Creating new emitter self.emitter_vector = Arrow(self.emitter.coordinates[0], self.emitter.coordinates[1], self.emitter.vector[0] / 20, self.emitter.vector[1] / 20, width=0.09) # Redraw plot self.figure.canvas.draw_idle()
def createPlot(self, fig=None, ax=None): self.timeOfLastPlot = -1 if (fig is None): self.fig = plt.figure() else: self.fig = fig if (ax is None): self.ax = self.fig.add_subplot(111) else: self.ax = ax # for lidar in self.vehicle.lidarArray: pm = [ pm.coords if pm is not None else None for pm in self.vehicle.lidar.read() ] bodyLine, = self.ax.plot(pm, 'r-', linewidth=0.1) self.bodyLines.append(bodyLine) (verticesX, verticesY) = self.centerBody.getDrawingVertex() self.centerBodyLine, = self.ax.plot(verticesX, verticesY, 'r') self.centerBodyArrow = Arrow( self.centerBody.x, self.centerBody.y, 0.1 * self.centerBody.v * cos(self.centerBody.orientation), 0.1 * self.centerBody.v * sin(self.centerBody.orientation), color='c') self.ax.add_patch(self.centerBodyArrow) self.radiusCircle = Circle((self.centerBody.x, self.centerBody.y), self.mapRadius, color='k', linestyle=':', fill=False) self.ax.add_patch(self.radiusCircle) self.ax.set_xlim([ self.centerBody.x - self.mapRadius * 1.1, self.centerBody.x + self.mapRadius * 1.1 ]) self.ax.set_ylim([ self.centerBody.y - self.mapRadius * 1.1, self.centerBody.y + self.mapRadius * 1.1 ]) self.ax.set_xlabel('Distance X') self.ax.set_ylabel('Distance Y')
def draw_arrow_inset(savefn, vx, vy, **kwargs): if ax._myarrow: ax._myarrow.remove() ax._myarrow = Arrow(0,0,vx,vy, width=0.5, **kwargs) ax.add_patch(ax._myarrow) fig.savefig(savefn, transparent=True)
def __call__(self, plot): from matplotlib.patches import Arrow # Now convert the pixels to code information x, y = self.convert_to_pixels(plot, self.pos) dx, dy = self.convert_to_pixels(plot, self.code_size, False) arrow = Arrow(x, y, dx, dy, **self.plot_args) plot._axes.add_patch(arrow)
def lb2D(): # define some colors colors = iter(cm.rainbow(np.linspace(0, 1, 9))) for offset in list(product([-1, 0, 1], repeat=2)): origin = [0.5, 0.5] rect = Rectangle( (0 + offset[0], 0 + offset[1]), # xy 1, # width 1, # height ec="black", # edge color fc=[0, 0, 0, 0], # face color = transparent zorder=1) # specify stacking ax2.add_patch(rect) if offset[0] != 0 or offset[1] != 0: arrow = Arrow(origin[0], origin[1], offset[0], offset[1], width=0.5, color=next(colors), zorder=0) ax2.add_patch(arrow) # draw c_0 circ = Circle((origin[0], origin[1]), 0.125, color="black", zorder=2) ax2.add_patch(circ) fig2.savefig("d2q9.png")
def text(x, y, label, rot, f=None, **kwargs): """ :param x: x location :param y: y location :param label: the text label :param rot: rotation :param f: matplotlib figure object """ inch = (f.axes.get_xlim()[-1] - f.axes.get_xlim()[0]) / 5 if f is not None else 1 width = (f.axes.get_xlim()[-1] - f.axes.get_xlim()[0]) / 25 if f is not None else 1 rot = rot / 180 * math.pi arrow = Arrow(x, y, inch * math.cos(rot), inch * math.sin(rot), width=width, color='red') if f is None: plt.text(x, y, label, **kwargs) plt.gca().add_patch(arrow) plt.gca().axis('equal') else: f.axes.text(x, y, label, **kwargs) f.axes.add_patch(arrow) plt.show()
def fibplot(self): global ra,dec,coll_x,coll_y,coll_rad,out,coll_stat_coll_x,rest,coll_y_rest,skyxvec,skyyvec,trstar_az,trstar_alt,trstar_ra,trstar_dec,rafld,decfld,alt,az #out = self.circles(coll_x, coll_y, coll_rad, alpha=0.7, fc='none',ec='black') self.axes.cla() starind=np.where(coll_stat=='Star')[0] skyind=np.where(coll_stat=='Sky')[0] noneind=np.where(coll_stat=='None')[0] coll_x=np.array(coll_x) coll_y=np.array(coll_y) if starind.size: fib_star_x=coll_x[starind] fib_star_y=coll_y[starind] if skyind.size: fib_sky_x=coll_x[skyind] fib_sky_y=coll_y[skyind] if noneind.size: fib_none_x=coll_x[noneind] fib_none_y=coll_y[noneind] self.axes.scatter(az,alt,c='b') if starind.size: self.axes.scatter(fib_star_x,fib_star_y,c='g',s=100,alpha=0.9) if skyind.size: self.axes.scatter(fib_sky_x,fib_sky_y,c='b',s=100,alpha=0.5) if noneind.size: self.axes.scatter(fib_none_x,fib_none_y,c='r',s=100,alpha=0.5) self.axes.add_collection(out) self.axes.scatter(coll_x_rest,coll_y_rest,marker='+') box = AnchoredAuxTransformBox(self.axes.transData, loc=2,frameon=False) el = Arrow(0, 0, skyxvec, skyyvec, width=.001) box.drawing_area.add_artist(el) self.axes.add_artist(box) self.axes.set_xlim(trstar_az-((rafld/2)+2*coll_rad[0]),trstar_az+((rafld/2)+2*coll_rad[0])) self.axes.set_ylim(trstar_alt-((decfld/2)+2*coll_rad[0]),trstar_alt+((decfld/2)+2*coll_rad[0])) self.canvas.draw()
def plot_arrows(subplot, arrows, color=None, width=None, alpha=None): assert len(arrows) > 0 assert len(arrows[0]) == 2 dimension = len(arrows[0][0]) assert dimension in [2, 3] if dimension == 2: arrow_patches = [] for arrow in arrows: arrow_patches.append( Arrow(x=arrow[0][0], y=arrow[0][1], dx=arrow[1][0] - arrow[0][0], dy=arrow[1][1] - arrow[0][1], width=width)) subplot.add_collection( PatchCollection(arrow_patches, color=color, alpha=alpha)) if dimension == 3: for arrow in arrows: plot_point(subplot, 0.2 * arrow[0] + 0.8 * arrow[1], size=5, color="green")
def as_artist(self, origin=(0, 0), **kwargs): """ Matplotlib patch object for this region (`matplotlib.patches.Arrow`). Parameters ---------- origin : array_like, optional The ``(x, y)`` pixel position of the origin of the displayed image. Default is (0, 0). kwargs : `dict` All keywords that a `~matplotlib.patches.Arrow` object accepts Returns ------- patch : `~matplotlib.patches.Arrow` Matplotlib line patch """ # Long term we want to support DS9 lines with arrow heads # We may want to use Line2D instead of arrow for lines because the width # of the arrow is non-scalable in patches from matplotlib.patches import Arrow x = self.start.x - origin[0] y = self.start.y - origin[1] dx = self.end.x - self.start.x dy = self.end.y - self.start.y if not 'width' in kwargs: kwargs['width'] = .1 # Let the default width be .1 instead of 1. mpl_params = self.mpl_properties_default('patch') mpl_params.update(kwargs) return Arrow(x, y, dx, dy, **mpl_params)
def calculer(val): # Récupère les valeurs v0 = slider_v0.val alpha = slider_alpha.val tmax = int(2 * v0 * sin(alpha * pi / 180) / gterre) + 1 t = np.linspace(0, tmax, tmax * 10) # On modifie les coordonnées x = v0 * cos(alpha * pi / 180) * t y = -0.5 * gterre * t**2 + v0 * sin(alpha * pi / 180) * t l.set_xdata(x) l.set_ydata(y) # De v0 aussi global v0a v0x = v0 * cos(alpha * pi / 180) v0y = v0 * sin(alpha * pi / 180) v0a.remove() v0a = ax.add_patch(Arrow(0, 0, v0x, v0y, color='r', label='v0')) # Et de alpha global angle angle.remove() angle = ax.add_patch( Arc([0, 0], v0x, v0y, 0, 0, alpha, color='g', label='Alpha')) # On update le graphique ax.set_xlim([0, max(np.max(x), v0x) + 5]) ax.set_ylim([0, max(np.max(y), v0y) + 5]) fig.canvas.draw_idle()
def showKpts(self, kpts, img=None): """ Display given kpts. """ fig, ax = plt.subplots(1) if img is not None: self.showImg(img, wait=True, ax=ax) pv = np.zeros(14) px = np.zeros(14) py = np.zeros(14) for kpt in kpts: skeleton_color = np.random.rand(3) num_kpt = len(kpt['keypoints']) / 3 # always 14 assert num_kpt == 14, 'Expected 14 keypoints but found {}'.format( num_kpt) for i in range(int(num_kpt)): px[i] = kpt['keypoints'][3 * i] py[i] = kpt['keypoints'][3 * i + 1] pv[i] = kpt['keypoints'][3 * i + 2] kpt_pair = [[0, 1], [1, 2], [2, 3], [3, 4], [2, 5], [5, 6], [6, 7], [1, 8], [8, 9], [9, 10], [8, 11], [11, 12], [12, 13]] for p in kpt_pair: p0 = p[0] p1 = p[1] if pv[p0] == 0 or pv[p1] == 0: continue if pv[p0] == 2 or pv[p1] == 2: pcolor = 'blue' else: pcolor = 'red' ax.add_patch( Arrow(px[p0], py[p0], px[p1] - px[p0], py[p1] - py[p0], width=2.0, facecolor=skeleton_color, edgecolor=skeleton_color)) for i in range(int(num_kpt)): if pv[i] == 0: continue pcolor = 'none' if pv[i] == 1: pcolor = 'red' else: pcolor = 'blue' ax.add_patch( Circle((px[i], py[i]), radius=3, facecolor=pcolor, edgecolor=skeleton_color, linewidth=2.0)) self.waiting = False plt.axis('off') plt.show()
def arrow(self, start, end, width=1.0, fill=None, color=None, linewidth=1.0, *args, **kwargs): """ Start and end are (z, y) tuples. """ edgecolor, facecolor, fill_bool = self._get_edge_face_color( fill, color) x = start[0] y = start[1] dx = end[0] - x dy = end[1] - y r = Arrow(x, y, dx, dy, width=width, edgecolor=edgecolor, facecolor=facecolor, fill=fill_bool, linewidth=linewidth, *args, **kwargs) self.canvas.add_artist(r)
def animate (self, i): self.strzal = [] for j in range(len(self.elipsy)): self.elipsy[j].center = self.trajectory[i][j] strzalka = Arrow(self.strzalkia[i], self.strzalkib[i], dx1, dy1, width=1, color="r") self.strzal.append(self.ax.add_patch(strzalka)) return self.elipsy + self.strzal
def _draw_roi_mois(self, visualizer, roi, mois): ax = visualizer.output.ax linewidth = max(visualizer._default_font_size / 4, 1) * visualizer.output.scale if roi is not None: roi = Polygon(roi, fill=False, color='red') ax.add_patch(roi) if mois is not None: for label, moi in sorted(mois.items(), key=lambda x: int(x[0])): color = self.color_manager.get_color(('moi', label)) line = Polygon(moi, closed=False, fill=False, edgecolor=color, label=label, linewidth=linewidth) ax.add_patch(line) dx, dy = moi[-1][0] - moi[-2][0], moi[-1][1] - moi[-2][1] arrow = Arrow(*moi[-2], dx, dy, edgecolor=color, facecolor=color, width=5 * linewidth) ax.add_patch(arrow) ax.legend(loc=0)
def plot(self, draw=True): # for idx in range(len(self.vehicle.lidarArray)): idx = 0 lidar = self.vehicle.lidar pm_x = [(self.centerBody.x, pm.xy[0][0]) if pm is not None else None for pm in lidar.read()] pm_y = [(self.centerBody.y, pm.xy[1][0]) if pm is not None else None for pm in lidar.read()] bodyLine = self.bodyLines[idx] bodyLine.set_ydata(pm_y) bodyLine.set_xdata(pm_x) (verticesX, verticesY) = self.centerBody.getDrawingVertex() self.centerBodyLine.set_ydata(verticesY) self.centerBodyLine.set_xdata(verticesX) self.centerBodyArrow.remove() self.centerBodyArrow = Arrow( self.centerBody.x, self.centerBody.y, 0.1 * self.centerBody.v * cos(self.centerBody.orientation), 0.1 * self.centerBody.v * sin(self.centerBody.orientation), color='c') self.ax.add_patch(self.centerBodyArrow) self.radiusCircle.remove() self.radiusCircle = Circle((self.centerBody.x, self.centerBody.y), self.mapRadius, color='k', linestyle=':', fill=False) self.ax.add_patch(self.radiusCircle) self.ax.set_xlim([ self.centerBody.x - self.mapRadius * 1.1, self.centerBody.x + self.mapRadius * 1.1 ]) self.ax.set_ylim([ self.centerBody.y - self.mapRadius * 1.1, self.centerBody.y + self.mapRadius * 1.1 ]) if (draw): self.fig.canvas.draw() plt.pause(0.001)
def plot(self, ax=None, exaggeration=1, **kwargs): if ax is None: ax = plt.gca() # type: plt.gca() start = self.from_node.pos + exaggeration*self.from_node.radius*self._unit_vector delta = (self.length_m - exaggeration * (self.from_node.radius + self.to_node.radius)) * self._unit_vector artist = Arrow(*start, *delta, **{"width": exaggeration*self.flow_capacity*3.2/1800, **kwargs}) ax.add_patch(artist) return [artist]
def add_vector(self, cell, xvec, xdir, fill_color='red'): """ Draw an arrow typically symbolizing a neighbor connection. """ from matplotlib.patches import Arrow pos = np.dot(cell, xvec) dir = np.dot(cell, xdir) self.ax.add_patch(Arrow(pos[0], pos[1], dir[0], dir[1], width=0.2))
def arrow(x1, y1, x2, y2, width=0.2): return Arrow(x1, y1, x2 - x1, y2 - y1, lw=1, width=width, ec='k', color='k')