Python matplotlib.patches.Circle() Examples
The following are 30
code examples of matplotlib.patches.Circle().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
matplotlib.patches
, or try the search function
.
Example #1
Source File: proj3d.py From opticspy with MIT License | 7 votes |
def test_lines_dists(): import pylab ax = pylab.gca() xs, ys = (0,30), (20,150) pylab.plot(xs, ys) points = list(zip(xs, ys)) p0, p1 = points xs, ys = (0,0,20,30), (100,150,30,200) pylab.scatter(xs, ys) dist = line2d_seg_dist(p0, p1, (xs[0], ys[0])) dist = line2d_seg_dist(p0, p1, np.array((xs, ys))) for x, y, d in zip(xs, ys, dist): c = Circle((x, y), d, fill=0) ax.add_patch(c) pylab.xlim(-200, 200) pylab.ylim(-200, 200) pylab.show()
Example #2
Source File: plotting.py From kvae with MIT License | 6 votes |
def construct_ball_trajectory(var, r=1., cmap='Blues', start_color=0.4, shape='c'): # https://matplotlib.org/examples/color/colormaps_reference.html patches = [] for pos in var: if shape == 'c': patches.append(mpatches.Circle(pos, r)) elif shape == 'r': patches.append(mpatches.RegularPolygon(pos, 4, r)) elif shape == 's': patches.append(mpatches.RegularPolygon(pos, 6, r)) colors = np.linspace(start_color, .9, len(patches)) collection = PatchCollection(patches, cmap=cm.get_cmap(cmap), alpha=1.) collection.set_array(np.array(colors)) collection.set_clim(0, 1) return collection
Example #3
Source File: test_electrodes.py From pulse2percept with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_PointSource(): electrode = PointSource(0, 1, 2) npt.assert_almost_equal(electrode.x, 0) npt.assert_almost_equal(electrode.y, 1) npt.assert_almost_equal(electrode.z, 2) npt.assert_almost_equal(electrode.electric_potential(0, 1, 2, 1, 1), 1) npt.assert_almost_equal(electrode.electric_potential(0, 0, 0, 1, 1), 0.035, decimal=3) # Slots: npt.assert_equal(hasattr(electrode, '__slots__'), True) npt.assert_equal(hasattr(electrode, '__dict__'), False) # Plots: ax = electrode.plot() npt.assert_equal(len(ax.texts), 0) npt.assert_equal(len(ax.patches), 1) npt.assert_equal(isinstance(ax.patches[0], Circle), True)
Example #4
Source File: test_prima.py From pulse2percept with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_PhotovoltaicPixel(): electrode = PhotovoltaicPixel(0, 1, 2, 3, 4) npt.assert_almost_equal(electrode.x, 0) npt.assert_almost_equal(electrode.y, 1) npt.assert_almost_equal(electrode.z, 2) npt.assert_almost_equal(electrode.r, 3) npt.assert_almost_equal(electrode.a, 4) # Slots: npt.assert_equal(hasattr(electrode, '__slots__'), True) npt.assert_equal(hasattr(electrode, '__dict__'), False) # Plots: ax = electrode.plot() npt.assert_equal(len(ax.texts), 0) npt.assert_equal(len(ax.patches), 2) npt.assert_equal(isinstance(ax.patches[0], RegularPolygon), True) npt.assert_equal(isinstance(ax.patches[1], Circle), True) PhotovoltaicPixel(0, 1, 2, 3, 4)
Example #5
Source File: electrodes.py From pulse2percept with BSD 3-Clause "New" or "Revised" License | 6 votes |
def __init__(self, x, y, z): super(PointSource, self).__init__(x, y, z) self.plot_patch = Circle self.plot_kwargs = {'radius': 5, 'linewidth': 2, 'ec': (0.3, 0.3, 0.3, 1), 'fc': (0.8, 0.8, 0.8, 0.7)}
Example #6
Source File: vis_utils.py From nucleus7 with Mozilla Public License 2.0 | 6 votes |
def _draw_nucleotide_body(nucleotide, center, subplot: plt_axes.Subplot, radius=10.0): nucleotide_color, nucleotide_base_class = _get_nucleotide_color(nucleotide) nucleotide_name = nucleotide.name if len(nucleotide_name) > 10: nucleotide_name = nucleotide_name.replace("_", "_\n") nucleotide_body = patches.Circle( center, radius=radius, color=nucleotide_color) text_object = subplot.text( center[0], center[1], nucleotide_name, va="center", ha="center") text_object.draw(subplot.figure.canvas.renderer) subplot.add_patch(nucleotide_body) nucleotide_body.add_callback( partial(_nucleotide_name_callback, text_object=text_object)) nucleotide_body.set_label(":".join([nucleotide_base_class.__name__, nucleotide.name])) nucleotide_body.set_picker(True) return nucleotide_body
Example #7
Source File: bbox.py From oft with MIT License | 6 votes |
def draw_bbox2d(objects, color='k', ax=None): limits = ax.axis() for obj in objects: x, _, z = obj.position l, _, w = obj.dimensions # Setup transform t = transforms.Affine2D().rotate(obj.angle + math.pi/2) t = t.translate(x, z) + ax.transData # Draw 2D object bounding box rect = Rectangle((-w/2, -l/2), w, l, edgecolor=color, transform=t, fill=False) ax.add_patch(rect) # Draw dot indicating object center center = Circle((x, z), 0.25, facecolor='k') ax.add_patch(center) ax.axis(limits) return ax
Example #8
Source File: coverage.py From YAFS with MIT License | 6 votes |
def __init__(self, map, points,radius): self.points = points self.radius = radius #radius in km #Points on the map projection self.points_to_map = [map.to_pixels(p[0], p[1]) for p in self.points] # Radius in the map projection b = self.__geodesic_point_buffer(points[0][0], points[0][1], self.radius) bonmap = map.to_pixels(b[0]) ponmap = map.to_pixels(points[0][0],points[0][1]) distance = math.sqrt(math.pow((bonmap[0]-ponmap[0]),2)+math.pow((bonmap[1]-ponmap[1]),2)) self.radius_on_coordinates = distance # Region on the map projection self.regions_to_map = [Circle((region[0],region[1]),self.radius_on_coordinates) for region in self.points_to_map] # Color of the regions self.cmap = plt.cm.Accent self.colors_cells = self.cmap(np.linspace(0., 1., len(self.points)))[:, :3]
Example #9
Source File: train.py From spinalcordtoolbox with MIT License | 6 votes |
def create_qc(fname_in, fname_gt, fname_out): img, gt = Image(fname_in), Image(fname_gt) img.change_orientation('RPI') gt.change_orientation('RPI') coord_c2c3 = np.where(gt.data == 1) y_c2c3, z_c2c3 = coord_c2c3[1][0], coord_c2c3[2][0] sag_slice = img.data[0, :, :] del img, gt ax = plt.gca() ax.imshow(sag_slice, interpolation='nearest', cmap='gray', aspect='auto') circ = Circle((z_c2c3, y_c2c3), 2, facecolor='chartreuse') ax.add_patch(circ) ax.get_xaxis().set_visible(False) ax.get_yaxis().set_visible(False) plt.savefig(fname_out) plt.close()
Example #10
Source File: test_axes.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_axisbelow(): # Test 'line' setting added in 6287. # Show only grids, not frame or ticks, to make this test # independent of future change to drawing order of those elements. fig, axs = plt.subplots(ncols=3, sharex=True, sharey=True) settings = (False, 'line', True) for ax, setting in zip(axs, settings): ax.plot((0, 10), (0, 10), lw=10, color='m') circ = mpatches.Circle((3, 3), color='r') ax.add_patch(circ) ax.grid(color='c', linestyle='-', linewidth=3) ax.tick_params(top=False, bottom=False, left=False, right=False) for spine in ax.spines.values(): spine.set_visible(False) ax.set_axisbelow(setting)
Example #11
Source File: proj3d.py From matplotlib-4-abaqus with MIT License | 6 votes |
def test_lines_dists(): import pylab ax = pylab.gca() xs, ys = (0,30), (20,150) pylab.plot(xs, ys) points = zip(xs, ys) p0, p1 = points xs, ys = (0,0,20,30), (100,150,30,200) pylab.scatter(xs, ys) dist = line2d_seg_dist(p0, p1, (xs[0], ys[0])) dist = line2d_seg_dist(p0, p1, np.array((xs, ys))) for x, y, d in zip(xs, ys, dist): c = Circle((x, y), d, fill=0) ax.add_patch(c) pylab.xlim(-200, 200) pylab.ylim(-200, 200) pylab.show()
Example #12
Source File: proj3d.py From Computable with MIT License | 6 votes |
def test_lines_dists(): import pylab ax = pylab.gca() xs, ys = (0,30), (20,150) pylab.plot(xs, ys) points = zip(xs, ys) p0, p1 = points xs, ys = (0,0,20,30), (100,150,30,200) pylab.scatter(xs, ys) dist = line2d_seg_dist(p0, p1, (xs[0], ys[0])) dist = line2d_seg_dist(p0, p1, np.array((xs, ys))) for x, y, d in zip(xs, ys, dist): c = Circle((x, y), d, fill=0) ax.add_patch(c) pylab.xlim(-200, 200) pylab.ylim(-200, 200) pylab.show()
Example #13
Source File: geo.py From ImageFusion with MIT License | 5 votes |
def _gen_axes_patch(self): return Circle((0.5, 0.5), 0.5)
Example #14
Source File: DOTA.py From RoITransformer_DOTA with MIT License | 5 votes |
def showAnns(self, objects, imgId, range): """ :param catNms: category names :param objects: objects to show :param imgId: img to show :param range: display range in the img :return: """ img = self.loadImgs(imgId)[0] plt.imshow(img) plt.axis('off') ax = plt.gca() ax.set_autoscale_on(False) polygons = [] color = [] circles = [] r = 5 # pdb.set_trace() for obj in objects: if obj['difficult'] != '0': continue c = (np.random.random((1, 3)) * 0.6 + 0.4).tolist()[0] poly = obj['poly'] import pdb # pdb.set_trace() polygons.append(Polygon(poly)) color.append(c) point = poly[0] circle = Circle((point[0], point[1]), r) circles.append(circle) p = PatchCollection(polygons, facecolors=color, linewidths=0, alpha=0.4) ax.add_collection(p) p = PatchCollection(polygons, facecolors='none', edgecolors=color, linewidths=2) ax.add_collection(p) p = PatchCollection(circles, facecolors='red') ax.add_collection(p) plt.show()
Example #15
Source File: coverage.py From YAFS with MIT License | 5 votes |
def update_coverage_of_endpoints(self, map, points): """ It updates the points, regions and colors in case of endpoints and mobile-endpoints changes Args: map: points: """ self.points = points self.points_to_map = [map.to_pixels(p[0], p[1]) for p in self.points] self.regions_to_map = [Circle((region[0], region[1]), self.radius_on_coordinates) for region in self.points_to_map] self.colors_cells = self.cmap(np.linspace(0., 1., len(self.points)))[:, :3]
Example #16
Source File: anchored_artists.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def draw_circle(ax): """ Draw a circle in axis coordinates """ from matplotlib.patches import Circle ada = AnchoredDrawingArea(20, 20, 0, 0, loc='upper right', pad=0., frameon=False) p = Circle((10, 10), 10) ada.da.add_artist(p) ax.add_artist(ada)
Example #17
Source File: labeling_toolbox.py From DeepLabCut with GNU Lesser General Public License v3.0 | 5 votes |
def plot(self, img): """ Plots and call auxfun_drag class for moving and removing points. """ self.drs = [] self.updatedCoords = [] for bpindex, bp in enumerate(self.bodyparts): color = self.colormap(self.norm(self.colorIndex[bpindex])) self.points = [ self.dataFrame[self.scorer][bp]["x"].values[self.iter], self.dataFrame[self.scorer][bp]["y"].values[self.iter], ] circle = [ patches.Circle( (self.points[0], self.points[1]), radius=self.markerSize, fc=color, alpha=self.alpha, ) ] self.axes.add_patch(circle[0]) self.dr = auxfun_drag_label.DraggablePoint( circle[0], self.bodyparts[bpindex] ) self.dr.connect() self.dr.coords = MainFrame.getLabels(self, self.iter)[bpindex] self.drs.append(self.dr) self.updatedCoords.append(self.dr.coords) if np.isnan(self.points)[0] == False: self.buttonCounter.append(bpindex) self.figure.canvas.draw() return self.buttonCounter
Example #18
Source File: custom_projection.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def _gen_axes_patch(self): """ Override this method to define the shape that is used for the background of the plot. It should be a subclass of Patch. In this case, it is a Circle (that may be warped by the axes transform into an ellipse). Any data and gridlines will be clipped to this shape. """ return Circle((0.5, 0.5), 0.5)
Example #19
Source File: anatomy.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def circle(x, y, radius=0.15): from matplotlib.patches import Circle from matplotlib.patheffects import withStroke circle = Circle((x, y), radius, clip_on=False, zorder=10, linewidth=1, edgecolor='black', facecolor=(0, 0, 0, .0125), path_effects=[withStroke(linewidth=5, foreground='w')]) ax.add_artist(circle)
Example #20
Source File: whats_new_98_4_fancy.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def make_arrowstyles(ax): styles = mpatch.ArrowStyle.get_styles() ax.set_xlim(0, 4) ax.set_ylim(0, figheight) for i, (stylename, styleclass) in enumerate(sorted(styles.items())): y = (float(len(styles)) -0.25 - i) # /figheight p = mpatch.Circle((3.2, y), 0.2, fc="w") ax.add_patch(p) ax.annotate(stylename, (3.2, y), (2., y), #xycoords="figure fraction", textcoords="figure fraction", ha="right", va="center", size=fontsize, arrowprops=dict(arrowstyle=stylename, patchB=p, shrinkA=5, shrinkB=5, fc="w", ec="k", connectionstyle="arc3,rad=-0.05", ), bbox=dict(boxstyle="square", fc="w")) ax.xaxis.set_visible(False) ax.yaxis.set_visible(False)
Example #21
Source File: geo.py From GraphicDesignPatternByPython with MIT License | 5 votes |
def _gen_axes_patch(self): return Circle((0.5, 0.5), 0.5)
Example #22
Source File: plotting.py From orbital with MIT License | 5 votes |
def _plot_body(self, orbit): color = '#EBEBEB' if orbit.body.plot_color is not None: color = orbit.body.plot_color self.axes.add_patch(Circle((0, 0), orbit.body.mean_radius / kilo, linewidth=0, color=color))
Example #23
Source File: test_axes.py From neural-network-animation with MIT License | 5 votes |
def test_mixed_collection(): from matplotlib import patches from matplotlib import collections x = list(xrange(10)) # First illustrate basic pyplot interface, using defaults where possible. fig = plt.figure() ax = fig.add_subplot(1, 1, 1) c = patches.Circle((8, 8), radius=4, facecolor='none', edgecolor='green') # PDF can optimize this one p1 = collections.PatchCollection([c], match_original=True) p1.set_offsets([[0, 0], [24, 24]]) p1.set_linewidths([1, 5]) # PDF can't optimize this one, because the alpha of the edge changes p2 = collections.PatchCollection([c], match_original=True) p2.set_offsets([[48, 0], [-32, -16]]) p2.set_linewidths([1, 5]) p2.set_edgecolors([[0, 0, 0.1, 1.0], [0, 0, 0.1, 0.5]]) ax.patch.set_color('0.5') ax.add_collection(p1) ax.add_collection(p2) ax.set_xlim(0, 16) ax.set_ylim(0, 16)
Example #24
Source File: polar.py From neural-network-animation with MIT License | 5 votes |
def _gen_axes_patch(self): return Circle((0.5, 0.5), 0.5)
Example #25
Source File: geo.py From neural-network-animation with MIT License | 5 votes |
def _gen_axes_patch(self): return Circle((0.5, 0.5), 0.5)
Example #26
Source File: parse_svg.py From pylustrator with GNU General Public License v3.0 | 5 votes |
def patch_circle(node: minidom.Element, trans: mtransforms.Transform, style: dict, ids: dict) -> mpatches.Circle: """ draw a svg circle node as a circle patch element into the figure (with the given transformation and style) """ if node.getAttribute("d") != "": return patch_path(node, trans, style, ids) return mpatches.Circle(xy=(float(node.getAttribute("cx")), float(node.getAttribute("cy"))), radius=float(node.getAttribute("r")), transform=trans)
Example #27
Source File: parse_svg.py From pylustrator with GNU General Public License v3.0 | 5 votes |
def clone_patch(patch: mpatches.Patch) -> mpatches.Patch: """ clone a patch element with the same properties as the given patch """ if isinstance(patch, mpatches.Rectangle): return mpatches.Rectangle(xy=patch.get_xy(), width=patch.get_width(), height=patch.get_height()) if isinstance(patch, mpatches.Circle): return mpatches.Circle(xy=patch.get_xy(), radius=patch.get_radius()) if isinstance(patch, mpatches.Ellipse): return mpatches.Ellipse(xy=patch.get_xy(), width=patch.get_width(), height=patch.get_height()) if isinstance(patch, mpatches.PathPatch): return mpatches.PathPatch(patch.get_path())
Example #28
Source File: PlotMatplot.py From Grid2Op with Mozilla Public License 2.0 | 5 votes |
def _draw_gen_bus(self, pos_x, pos_y, norm_dir_x, norm_dir_y, bus_id): center_x = pos_x + norm_dir_x * self._sub_radius center_y = pos_y + norm_dir_y * self._sub_radius face_color = self._line_bus_face_colors[bus_id] patch = patches.Circle((center_x, center_y), radius=self._line_bus_radius, facecolor=face_color) self.ax.add_patch(patch)
Example #29
Source File: frame_extraction_toolbox.py From DeepLabCut with GNU Lesser General Public License v3.0 | 5 votes |
def plot_labels(self): """ Plots the labels of the analyzed video """ self.vid.set(1, self.currFrame) ret, frame = self.vid.read() if ret: frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) self.norm = mcolors.Normalize(vmin=np.min(frame), vmax=np.max(frame)) self.colorIndex = np.linspace( np.min(frame), np.max(frame), len(self.bodyparts) ) divider = make_axes_locatable(self.axes) cax = divider.append_axes("right", size="5%", pad=0.05) cbar = self.figure.colorbar( self.ax, cax=cax, spacing="proportional", ticks=self.colorIndex ) cbar.set_ticklabels(self.bodyparts) for bpindex, bp in enumerate(self.bodyparts): color = self.colormap(self.norm(self.colorIndex[bpindex])) self.points = [ self.Dataframe[self.scorer][bp]["x"].values[self.currFrame], self.Dataframe[self.scorer][bp]["y"].values[self.currFrame], 1.0, ] circle = [ patches.Circle( (self.points[0], self.points[1]), radius=self.markerSize, fc=color, alpha=self.alpha, ) ] self.axes.add_patch(circle[0]) self.figure.canvas.draw()
Example #30
Source File: test_axes.py From python3_ios with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_mixed_collection(): from matplotlib import patches from matplotlib import collections x = list(range(10)) # First illustrate basic pyplot interface, using defaults where possible. fig = plt.figure() ax = fig.add_subplot(1, 1, 1) c = patches.Circle((8, 8), radius=4, facecolor='none', edgecolor='green') # PDF can optimize this one p1 = collections.PatchCollection([c], match_original=True) p1.set_offsets([[0, 0], [24, 24]]) p1.set_linewidths([1, 5]) # PDF can't optimize this one, because the alpha of the edge changes p2 = collections.PatchCollection([c], match_original=True) p2.set_offsets([[48, 0], [-32, -16]]) p2.set_linewidths([1, 5]) p2.set_edgecolors([[0, 0, 0.1, 1.0], [0, 0, 0.1, 0.5]]) ax.patch.set_color('0.5') ax.add_collection(p1) ax.add_collection(p2) ax.set_xlim(0, 16) ax.set_ylim(0, 16)