def _make_barb(self, temperature, theta, speed, angle): """Add the barb to the plot at the specified location.""" u, v = self._uv(speed, angle) if 0 < speed < _BARB_BINS[0]: # Plot the missing barbless 1-2 knots line. length = self._kwargs['length'] pivot_points = dict(tip=0.0, middle=-length / 2.) pivot = self._kwargs.get('pivot', 'tip') offset = pivot_points[pivot] verts = [(0.0, offset), (0.0, length + offset)] rangle = math.radians(-angle) verts = mtransforms.Affine2D().rotate(rangle).transform(verts) codes = [Path.MOVETO, Path.LINETO] path = Path(verts, codes) size = length**2 / 4 xy = np.array([[temperature, theta]]) barb = PathCollection([path], (size, ), offsets=xy, transOffset=self._transform, **self._custom_kwargs) barb.set_transform(mtransforms.IdentityTransform()) self.axes.add_collection(barb) else: barb = plt.barbs(temperature, theta, u, v, transform=self._transform, **self._kwargs) return barb
def _make_barb(self, temperature, theta, speed, angle): """Add the barb to the plot at the specified location.""" u, v = self._uv(speed, angle) if 0 < speed < _BARB_BINS[0]: # Plot the missing barbless 1-2 knots line. length = self._kwargs['length'] pivot_points = dict(tip=0.0, middle=-length / 2.) pivot = self._kwargs.get('pivot', 'tip') offset = pivot_points[pivot] verts = [(0.0, offset), (0.0, length + offset)] rangle = math.radians(-angle) verts = mtransforms.Affine2D().rotate(rangle).transform(verts) codes = [Path.MOVETO, Path.LINETO] path = Path(verts, codes) size = length ** 2 / 4 xy = np.array([[temperature, theta]]) barb = PathCollection([path], (size,), offsets=xy, transOffset=self._transform, **self._custom_kwargs) barb.set_transform(mtransforms.IdentityTransform()) self.axes.add_collection(barb) else: barb = plt.barbs(temperature, theta, u, v, transform=self._transform, **self._kwargs) return barb
def _generate_node_artist(pos, styles, *, ax): N = len(pos) proto_node = next(iter(pos)) x = np.zeros(N) * np.nan y = np.zeros(N) * np.nan properties = { k: [None] * N for k in styles[proto_node] if k in _VALID_NODE_STYLE } for j, node in enumerate(pos): x[j], y[j] = pos[node] for key, values in properties.items(): values[j] = styles[node][key] key_map = { 'size': 'sizes', 'color': 'facecolors', 'shape': 'marker', 'width': 'linewidths', 'edgecolor': 'edgecolors' } renamed_properties = {key_map[k]: v for k, v in properties.items()} markers = renamed_properties.pop('marker', None) if markers is None: paths = (MarkerStyle('o'), ) else: paths = [MarkerStyle(m) for m in markers] paths = [p.get_path().transformed(p.get_transform()) for p in paths] offsets = np.column_stack([x, y]) node_art = PathCollection(paths, offsets=offsets, transOffset=ax.transData, **renamed_properties) node_art.set_transform(mtransforms.IdentityTransform()) ax.add_collection(node_art) ax.autoscale_view() return node_art
def get_patches(self, ax): ranges = LineCollection(self._cap_ranges, linestyle="solid") links = LineCollection(self._oob_links, linestyle="dotted", colors=colorConverter.to_rgba_array("#808080")) color = colorConverter.to_rgba_array("#DC143C") scales = np.array((20, )) marker_obj = MarkerStyle("o") path = marker_obj.get_path().transformed(marker_obj.get_transform()) offsets = PathCollection((path, ), scales, facecolors=color, offsets=self._oob_offsets, transOffset=ax.transData) offsets.set_transform(IdentityTransform()) return [ranges, links, offsets]
def my_scatter(self, ax, x, y): from matplotlib.collections import PathCollection from matplotlib.path import Path import matplotlib.transforms as mtransforms phi = np.linspace(0, 2 * np.pi, 100) # Scale, in pixel coordinates rad = 2 x_circle = np.cos(phi) * rad y_circle = np.sin(phi) * rad verts = np.vstack([x_circle, y_circle]).T path = Path(verts, closed=False) collection = PathCollection( [path], facecolor='blue', edgecolor='black', transOffset=ax.transData, ) collection.set_transform(mtransforms.IdentityTransform()) ax.add_collection(collection, autolim=True) ax.autoscale()
px = np.random.rand(10) py = np.random.rand(10) offsets = np.ma.column_stack([px, py]) #%% 1 fig, ax = plt.subplots() reduction = 50 c = Path.unit_circle() c = c.transformed(Affine2D().scale(0.5 * reduction)) collection = PathCollection( (c,), offsets=offsets, transOffset = ax.transData, edgecolor='black', facecolor=(0, 0, 0, .0125), linewidth=1 ) collection.set_transform(IdentityTransform()) ax.add_collection( collection ) #%% 2 collection.set_path_effects([withStroke(linewidth=5, foreground='r')]) collection.set_path_effects([]) collection.get_path_effects()