def __init__(self, xy, numVertices, radius=5, orientation=0, **kwargs): """ Constructor arguments: *xy* A length 2 tuple (*x*, *y*) of the center. *numVertices* the number of vertices. *radius* The distance from the center to each of the vertices. *orientation* rotates the polygon (in radians). Valid kwargs are: %(Patch)s """ self._xy = xy self._numVertices = numVertices self._orientation = orientation self._radius = radius self._path = Path.unit_regular_polygon(numVertices) self._poly_transform = transforms.Affine2D() self._update_transform() Patch.__init__(self, **kwargs)
def _gen_axes_spines(self): spine = Spine(axes=self, spine_type='circle', path=Path.unit_regular_polygon(4)) spine.set_transform(Affine2D().scale(.5).translate(.5, .5) + self.transAxes) return {'polar': spine}
def _gen_axes_spines(self): spine = Spine(axes=self, spine_type='circle', path=Path.unit_regular_polygon(numVars)) # unit_regular_polygon gives a polygon of radius 1 # centered at(0, 0) but we want a polygon of radius 0.5 # centered at (0.5, 0.5) in axes coordinates. spine.set_transform(Affine2D().scale(.5).translate(.5, .5) + self.transAxes) return {'polar': spine}
def draw_generic(ax, x, y, name, n_points=6, scale=0.1): unit_polygon = Path.unit_regular_polygon(n_points) path = Path(unit_polygon.vertices * scale, unit_polygon.codes) trans = matplotlib.transforms.Affine2D().translate(x, y) t_path = path.transformed(trans) name = TextPath((x - (0.35 * scale), y), s=name, size=2 * scale * .25) patch = patches.PathPatch(t_path, facecolor="white", lw=line_weight, zorder=2) a = ax.add_patch(patch) patch = patches.PathPatch(name, lw=line_weight, zorder=2) s = ax.add_patch(patch) ma = MonosaccharidePatch(saccharide_shape=(a,), saccharide_label=(s,)) return ma
def __init__(self, shape, xy, radius, **kwargs): self.shape = shape self.xy = xy self.radius = radius if shape == 'o': # circle self.numVertices = None self.orientation = 0 elif shape == '^': # triangle up self.numVertices = 3 self.orientation = 0 elif shape == '<': # triangle left self.numVertices = 3 self.orientation = np.pi * 0.5 elif shape == 'v': # triangle down self.numVertices = 3 self.orientation = np.pi elif shape == '>': # triangle right self.numVertices = 3 self.orientation = np.pi * 1.5 elif shape == 's': # square self.numVertices = 4 self.orientation = np.pi * 0.25 elif shape == 'd': # diamond self.numVertices = 4 self.orientation = np.pi * 0.5 elif shape == 'p': # pentagon self.numVertices = 5 self.orientation = 0 elif shape == 'h': # hexagon self.numVertices = 6 self.orientation = 0 elif shape == '8': # octagon self.numVertices = 8 self.orientation = 0 else: raise ValueError( "Node shape should be one of: 'so^>v<dph8'. Current shape:{}". format(shape)) if self.shape == 'o': # circle self.linewidth_correction = 2 self._path = Path.circle() else: # regular polygon self.linewidth_correction = 2 * np.sin( np.pi / self.numVertices ) # derives from the ratio between a side and the radius in a regular polygon. self._path = Path.unit_regular_polygon(self.numVertices) self._patch_transform = transforms.Affine2D() super().__init__(path=self._path, **kwargs)
def _gen_axes_spines(self): if frame == 'Circle': return super()._gen_axes_spines() elif frame == 'polygon': # spine_type must be 'left'/'right'/'top'/'bottom'/'circle'. from matplotlib.path import Path from matplotlib.spines import Spine from matplotlib.transforms import Affine2D spine = Spine(axes=self, spine_type='circle', path=Path.unit_regular_polygon(nvars)) # unit_regular_polygon gives a polygon of radius 1 centered at (0, 0) but we want a polygon of radius 0.5 centered at (0.5, 0.5) in axes coordinates. spine.set_transform(Affine2D().scale(.5).translate(.5, .5) + self.transAxes) return {'polar': spine}
def _gen_axes_spines(self): if frame == 'circle': return super()._gen_axes_spines() elif frame == 'polygon': # spine_type must be 'left'/'right'/'top'/'bottom'/'circle'. spine = Spine(axes=self, spine_type='circle', path=Path.unit_regular_polygon(num_vars)) # unit_regular_polygon gives a polygon of radius 1 centered at # (0, 0) but we want a polygon of radius 0.5 centered at (0.5, # 0.5) in axes coordinates. spine.set_transform(Affine2D().scale(.5).translate(.5, .5) + self.transAxes) return {'polar': spine} else: raise ValueError("unknown value for 'frame': %s" % frame)
def __init__(self, xy, numVertices, radius=5, orientation=0, **kwargs): """ xy is a length 2 tuple (the center) numVertices is the number of vertices. radius is the distance from the center to each of the vertices. orientation is in radians and rotates the polygon. Valid kwargs are: %(Patch)s """ self._xy = xy self._numVertices = numVertices self._orientation = orientation self._radius = radius self._path = Path.unit_regular_polygon(numVertices) self._poly_transform = transforms.Affine2D() self._update_transform() Patch.__init__(self, **kwargs)
def _set_numvertices(self, numVertices): self._numVertices = numVertices self._path = Path.unit_regular_polygon(numVertices)
# return (a,) draw_map[ResidueShape.square] = draw_square unit_rectangle = Path.unit_rectangle() def draw_triangle(ax, x, y, color, scale=0.1): path = Path(unit_triangle.vertices * scale, unit_triangle.codes) trans = matplotlib.transforms.Affine2D().translate(x, y).rotate_deg_around(x, y, -90) t_path = path.transformed(trans) patch = patches.PathPatch(t_path, facecolor=color.value, lw=line_weight, zorder=2) a = ax.add_patch(patch) ma = MonosaccharidePatch(saccharide_shape=(a,)) return ma # return (a,) draw_map[ResidueShape.triangle] = draw_triangle unit_triangle = Path.unit_regular_polygon(3) def draw_bisected_square(ax, x, y, color, scale=0.1): lower_verts = (np.array([ (0., 0.), (1.0, 0), (0, 1.0), (0, 0), (0., 0.), ]) - 0.5) / 5 upper_verts = (np.array([ (1., 1.), (1.0, 0), (0, 1.0),
""" Draw. If frame is polygon, make gridlines polygon-shaped """ if frame == 'polygon': gridlines = self.yaxis.get_gridlines() for gl in gridlines: gl.get_path()._interpolation_steps = num_vars super().draw(renderer) def _gen_axes_spines(self): if frame == 'circle': return super()._gen_axes_spines() elif frame == 'polygon': # spine_type must be 'left'/'right'/'top'/'bottom'/'circle'. spine = Spine(axes=self, spine_type='circle', path=Path.unit_regular_polygon(num_vars)) # unit_regular_polygon gives a polygon of radius 1 centered at # (0, 0) but we want a polygon of radius 0.5 centered at (0.5, # 0.5) in axes coordinates. spine.set_transform(Affine2D().scale(.5).translate(.5, .5) + self.transAxes) return {'polar': spine} else: raise ValueError("unknown value for 'frame': %s" % frame) register_projection(RadarAxes) return theta top_10_plot = top_10[['Name','Age','Nationality','Club','Position','Pace','Shooting',