def add_circles(treeplot, nodes, colors="g", size=15, xoff=0, yoff=0, vis=True): """ Draw circles on plot Args: nodes: A node object or list of Node objects or label or list of labels colors: Str or list of strs. Colors of the circles. Optional, defaults to 'g' (green) size (float): Size of the circles. Optional, defaults to 15 xoff, yoff (float): X and Y offset. Optional, defaults to 0. """ points = xy(treeplot, nodes) trans = offset_copy( treeplot.transData, fig=treeplot.figure, x=xoff, y=yoff, units='points' ) col = CircleCollection( sizes=(pi*size*size*0.25,), offsets=points, facecolors=colors, transOffset=trans, edgecolors='none', zorder=1 ) col.set_visible(vis) treeplot.add_collection(col) treeplot.figure.canvas.draw_idle()
def shape(self, height, yrange, rotated): g = rlg2mpl.Group() (X, Y, I) = (0, 1, 2) #scaled_axes = [[X, I], [I, Y]][rotated] scaled_axes = [[X, X], [Y, Y]][rotated] scaled_axes = [[X, Y], [X, Y]][rotated] trans = TransformScalePart(g.combined_transform, scaled_axes) a = CircleCollection([.5], edgecolors=self.cvalues, facecolors=self.cvalues, offsets=self.offsets, transOffset=g.combined_transform) g.add(a) a.set_transform(trans) return g
def circles(plot, p, colors='g', size=15, xoff=0, yoff=0): """ Draw circles on plot Args: plot (Tree): A Tree plot instance p: A node object or list of Node objects colors: Str or list of strs. Colors of the circles. Optional, defaults to 'g' (green) size (float): Size of the circles. Optional, defaults to 15 xoff, yoff (float): X and Y offset. Optional, defaults to 0. """ points = _xy(plot, p) trans = offset_copy( plot.transData, fig=plot.figure, x=xoff, y=yoff, units='points' ) col = CircleCollection( sizes=(pi*size*size*0.25,), offsets=points, facecolors=colors, transOffset=trans, edgecolors='none' ) plot.add_collection(col) plot.figure.canvas.draw_idle() return col
def plot_structure(self, fig, n, global_axis=False): atom_positions = self.carbon_data.getStructure(n) sizes = self.calc_sizes_using_z_depth(atom_positions) ax = fig.add_subplot(111) # circles = np.ndarray(24) # for i in range(len(circles)) # circles[i] = Circle(atom_positions[:,0:2][i], radius = np.sqrt(sizes[i])) # pc = cc = CircleCollection(sizes=sizes, offsets=np.sort(atom_positions[:, 0:2], axis=2), transOffset=ax.transData, facecolors='gray', edgecolors='k') ax.add_collection(cc) if global_axis: xs = self.carbon_data.data_positions[:, :, 0] ys = self.carbon_data.data_positions[:, :, 1] ax.set_xlim(np.min(xs) - 1, np.max(xs) + 1) ax.set_ylim(np.min(ys) - 1, np.max(ys) + 1) else: ax.autoscale_view() ax.axis("off") return fig
def plot_rydberg_snap(snap, ax=None): """ Plots a single-channel Rydberg snapshot, optionally into the given `ax`. """ from matplotlib.collections import CircleCollection W, H = snap.shape[-1], snap.shape[-2] plt.rc('axes', linewidth=6) radius = 200 rads = radius * np.ones_like(snap.flatten()) lattice = np.stack(np.meshgrid(np.arange(W), np.arange(H)), axis=-1).reshape(-1, 2) if ax is None: fig, ax = plt.subplots(figsize=(5, 5)) circs = CircleCollection( rads, offsets=lattice, cmap='Purples', transOffset=ax.transData, edgecolors='black', linewidths=3, ) circs.set_array(snap.flatten()) ax.add_collection(circs) ax.autoscale_view() ax.set_aspect(1.0) ax.set_facecolor('xkcd:grey') ax.tick_params(axis='both', which='both', bottom=False, top=False, labelbottom=False, left=False, right=False, labelleft=False) return ax
y -= 1 # Circle collection # ---------------------------------------------------------------------------- n = 10 offsets = np.ones((n, 2)) offsets[:, 0], offsets[:, 1] = np.linspace(1, 10, n), y X, Y = offsets[:, 0], offsets[:, 1] sizes = np.linspace(25, 100, n) linewidths = np.linspace(1, 2, n) facecolors = ['%.1f' % c for c in np.linspace(0.25, 0.75, n)] collection = CircleCollection( sizes, # linewidths = linewidths, facecolors=facecolors, edgecolor="black", offsets=offsets, transOffset=ax.transData) ax.add_collection(collection) ax.text(X[0] - 0.25, y + 0.35, "Circle collection", size="small", ha="left", va="baseline") ax.text(X[-1] + 0.25, y + 0.35, "CircleCollection", color="blue",
# # * add_artist() # * add_line() # * add_collection() # * add_patch() # <codecell> from matplotlib.collections import CircleCollection fig = plt.figure() ax = fig.add_subplot(1, 1, 1) sizes = np.empty_like(x) sizes.fill(20) coll = CircleCollection(sizes, offsets=(x, y), transOffset=ax.transData, edgecolor='red', facecolor='cyan') ax.add_collection(coll) ax.autoscale_view() plt.draw() # <markdowncell> # Let's add a couple of "useful" patches to this. # <codecell> from matplotlib.patches import Circle, Rectangle circ = Circle((0, 0), radius=1.0,
def scatterplot(self, xdata, ydata, label=None, size=10, color=None, edgecolor=None, selectcolor=None, selectedge=None, xlabel=None, ylabel=None, y2label=None, xmin=None, xmax=None, ymin=None, ymax=None, title=None, grid=None, callback=None, **kw): if xlabel is not None: self.set_xlabel(xlabel) if ylabel is not None: self.set_ylabel(ylabel) if y2label is not None: self.set_y2label(y2label) if title is not None: self.set_title(title) if grid is not None: self.conf.show_grid = grid if callback is not None: self.lasso_callback = callback self.conf.plot_type = 'scatter' self.cursor_mode = 'lasso' if color is not None: self.conf.scatter_normalcolor = color if edgecolor is not None: self.conf.scatter_normaledge = edgecolor if selectcolor is not None: self.conf.scatter_selectcolor = selectcolor if selectedge is not None: self.conf.scatter_selectedge = selectedge axes = self.axes self.conf.user_limits[axes] = (xmin, xmax, ymin, ymax) self.conf.axes_traces = {axes: [0]} self.conf.set_trace_label('scatterplot') self.conf.set_trace_datarange( (min(xdata), max(xdata), min(ydata), max(ydata))) fcols = [to_rgba(self.conf.scatter_normalcolor) for x in xdata] ecols = [self.conf.scatter_normaledge] * len(xdata) self.conf.scatter_data = [(x, y) for x, y in zip(xdata, ydata)] self.conf.scatter_size = size self.conf.scatter_coll = CircleCollection( sizes=(size, ), facecolors=fcols, edgecolors=ecols, offsets=self.conf.scatter_data, transOffset=self.axes.transData) self.axes.add_collection(self.conf.scatter_coll) if self.conf.show_grid: for i in axes.get_xgridlines() + axes.get_ygridlines(): i.set_color(self.conf.gridcolor) i.set_zorder(-30) axes.grid(True) else: axes.grid(False) self.set_viewlimits() self.draw()
def freq_Scatter(parser, thrPrt=0.3, thrPep=0.5, analysis_name = "", Xlab = "", Ylab = "" ): """ plots an advanced scatter-plot for peptides and protein frequencies. :param parser: the parser that store the seq :param analysis_name: the analysis name :param thrPrt: the protein frequency threshold :param thrPep: the peptide frequency threshold :param Xlab: the label for X axe :param Ylab: the label for Y axe :return: the figure of the analysis plot - after it can be plotted on the screen or saved in a picture file :raises NoData: If there are not proteins or peptides frequencies values .. plot:: pyplots/scatter.py :include-source: """ # calculating the plotting seq x, y, z = parser.frequencyMatrix() if x and y and z: # definitions for the axes left, width = 0.1, 0.65 bottom, height = 0.1, 0.65 bottom_b = left_b = left+width+0.01 rect_scatter = [left, bottom, width, height] rect_box_x = [left, bottom_b, width, 0.2] rect_box_y = [left_b, bottom, 0.2, height] rect_leg = [left_b, bottom_b, 0.2, 0.2] # start with a rectangular Figure fig = plt.figure(scatter_plot_fig, figsize=(8,8)) axScatter = plt.axes(rect_scatter) axBoxx = plt.axes(rect_box_x, xticks=[], yticks=[]) axBoxy = plt.axes(rect_box_y, xticks=[], yticks=[]) axLeg = plt.axes(rect_leg, xticks=[], yticks=[]) # no labels import matplotlib.ticker nullfmt = matplotlib.ticker.NullFormatter() axBoxx.xaxis.set_major_formatter(nullfmt) axBoxx.yaxis.set_major_formatter(nullfmt) axBoxy.xaxis.set_major_formatter(nullfmt) axBoxy.yaxis.set_major_formatter(nullfmt) axLeg.xaxis.set_major_formatter(nullfmt) axLeg.yaxis.set_major_formatter(nullfmt) # scatter plot axScatter.scatter(x, y, s=z, alpha=0.75) axScatter.set_xlabel(Xlab) axScatter.set_ylabel(Ylab) axScatter.axhline(linewidth=2, color='r',linestyle='-.', y=thrPep) axScatter.axvline(linewidth=2, color='r',linestyle='-.', x=thrPrt) axScatter.set_xlim( (-0.1, 1.1) ) axScatter.set_ylim( (-0.1, 1.1) ) # x boxplot axBoxx.boxplot(x,vert = 0) axBoxx.set_xlim( axScatter.get_xlim() ) # title upside axBox axBoxx.set_title(analysis_name, x=0.6) # y box plot axBoxy.boxplot(y) axBoxy.set_ylim( axScatter.get_ylim() ) # Legend c_c = CircleCollection(sizes=(1, 10, 100), offsets=[(0.1, 0.5), (0.5, 0.5), (0.9, 0.5)], transOffset=axLeg.transData, alpha=0.75) axLeg.add_collection(c_c) plt.text(0.1, 0.3, "1", ha="center", size=8) plt.text(0.5, 0.3, "10", ha="center", size=8) plt.text(0.9, 0.3, "100", ha="center", size=8) fig.canvas.draw() return fig else: raise NoData, "There aren't about frequencies!!!"