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!!!"