def __getNormalization(self): if self._isLogScaleEnabled(): return lognorm() elif self._isNormalizedScaleEnabled(): return norm(vmin=0.0, vmax=1.0) return None
def draw_shotchart(xs, ys, pct): from matplotlib import pyplot as plot from matplotlib.colors import Normalize as norm plot.scatter(xs, ys, c=pct, marker='s', cmap=plot.cm.jet, norm=norm(vmin=0.25, vmax=0.85), s=100) plot.show()
def create_shotchart_plot(tups): from matplotlib import pyplot as plot from matplotlib.colors import Normalize as norm for (x, y, pct, op) in tups: plot.scatter(x, y, c=pct, alpha=op, marker='s', cmap=plot.cm.jet, norm=norm(vmin=0.25, vmax=0.7), s=50) return plot
def addSegmentedColorbar(ax, colors, vmin, vmax, label, logflag=0, fontsize=16, cmap_number=0, tick_tuple=None): ## find figure sizes fig = ax.get_figure() cur_height, cur_width = fig.get_size_inches() * fig.dpi offset = cmap_number * (150 / cur_width) ## make the colorbar axes ax1 = fig.add_axes([0.95 + offset, 0.125, 15. / cur_width, 0.75]) ## setup segmented colormap cmap = matplotlib.colors.ListedColormap(colors) cmap.set_over(colors[-1]) cmap.set_under(colors[0]) if logflag: ticks = 10**np.linspace(np.log10(vmin), np.log10(vmax), len(cmap.colors) + 1)[1:-1] norm = matplotlib.colors.LogNorm(vmin=vmin, vmax=vmax) tick_labels = [r"$10^{%.2f}$" % tick for tick in np.log10(ticks)] else: ticks = np.linspace(vmin, vmax, len(cmap.colors) + 1)[1:-1] norm = matplotlib.colors.Normalize(vmin=vmin, vmax=vmax) tick_labels = ticks ## allow explicit tick placement and labelling if tick_tuple is not None: ticks, tick_labels = tick_tuple cb = matplotlib.colorbar.ColorbarBase(ax1, cmap=cmap, norm=norm, extend='both', extendfrac=.05, extendrect=False, ticks=ticks, orientation='vertical') cb.set_label(label, fontsize=fontsize) cb.set_ticklabels(tick_labels) cb.ax.tick_params(labelsize=fontsize - 2) return lambda x: cmap(norm(x))
def addColorbar(ax, cmap, vmin, vmax, label, logflag=0, fontsize=16, cmap_number=0, tick_tuple=None): if logflag: from matplotlib.colors import LogNorm as norm ticks = np.linspace(np.log10(vmin), np.log10(vmax), 5, endpoint=True) tick_labels = [r"$10^{%.1f}$" % tick for tick in ticks] ticks = 10**ticks else: from matplotlib.colors import Normalize as norm ticks = np.linspace(vmin, vmax, 5, endpoint=True) tick_labels = ticks if tick_tuple is not None: ticks, tick_labels = tick_tuple fig = ax.get_figure() ## x,y of bottom left corner, width,height in percentage of figure size ## matches the default aspect ratio of matplotlib cur_size = fig.get_size_inches() * fig.dpi cur_height = cur_size[1] cur_width = cur_size[0] offset = 0.00 + cmap_number * (25 / cur_width + 50 / cur_width) ax1 = fig.add_axes([0.95 + offset, 0.125, 25. / cur_width, 0.75]) cb1 = matplotlib.colorbar.ColorbarBase(ax1, cmap=cmap, extend='both', extendfrac=0.05, norm=norm(vmin=vmin, vmax=vmax), orientation='vertical') cb1.set_label(label, fontsize=fontsize) cb1.set_ticks(ticks) cb1.set_ticklabels(tick_labels) cb1.ax.tick_params(labelsize=fontsize - 2) return cb1, ax1
def plott(x, y, Z): """Function for 3D plotting, edited from https://matplotlib.org/mpl_toolkits/mplot3d/tutorial.html """ fig = plt.figure() ax = fig.gca(projection='3d') surf = ax.plot_surface(x, y, Z, cmap=cm.coolwarm, linewidth=0, antialiased=False, norm=norm(vmin=0, vmax=0.3)) ax.set_xlabel('x') ax.set_ylabel('y') ax.view_init(40, 92) ax.set_zlim(0,0.5) # Add a color bar which maps values to colors. fig.colorbar(surf, shrink=0.5, aspect=5) plt.show()
def create_shotchart_png(tups): """ returns a stringIO object that stores the binary PNG data for a plot """ from matplotlib import pyplot as plot from matplotlib.colors import Normalize as norm for (x, y, pct, op) in tups: plot.scatter(x, y, c=pct, alpha=op, marker='s', cmap=plot.cm.jet, norm=norm(vmin=0.25, vmax=0.7), s=50, linewidths=0) out = StringIO.StringIO() plot.savefig(out, ext='png') plot.close() return out
def render(self): # render the image and centroid coordinate # load the region of interest within the image img = self.image[int(self.f), self.lims()['ylims'][0]:self.lims()['ylims'][1], self.lims()['xlims'][0]:self.lims()['xlims'][1]] # show the image, aximg is outputed to refresh its content # in order to navigate faster within the frames aximg = plt.imshow( img, norm=norm(vmin=np.amin(self.image), vmax=(np.amax(self.image) - self.saturation * (np.amax(self.image) - np.amin(self.image)) )), # intensity normalization cmap=self.cmap) # plot centroid axcentroid = plt.plot(self.centroid()[0] - self.lims()['xlims'][0], self.centroid()[1] - self.lims()['ylims'][0], marker=self.marker, markersize=self.markersize, color='red', markerfacecolor='none') # graphical parameters plt.xlabel("Pixels") plt.ylabel("Pixels") plt.title( self.trajectory.annotations()[ 'file' ] + ' ' + '\n' + \ 'trajectory ' + str( self.j + 1 ) + '/' + str( len( self.tlist ) ) + '; ' + 'frame ' + str( self.f - self.fmin ) + '/' + str( self.fmax - self.fmin ) + '; ' + \ r'$r=$' + str( self.r ) + '; ' + \ r'$s=$' + str( round( self.saturation , 2 ) ) ) self.canvas.draw() return [aximg, axcentroid[0]]
def addColorbar(ax, cmap, vmin, vmax, label, logflag=0, fontsize=12, cmap_number=0, tick_tuple=None, horizontal=False, span_full_figure=True): if logflag: from matplotlib.colors import LogNorm as norm ticks = np.linspace(np.log10(vmin), np.log10(vmax), 5, endpoint=True) ticks = 10**ticks tick_labels = [my_log_formatter(tick, None) for tick in ticks] else: from matplotlib.colors import Normalize as norm ticks = np.linspace(vmin, vmax, 5, endpoint=True) tick_labels = ["%.2f" % tick for tick in ticks] if tick_tuple is not None: ticks, tick_labels = tick_tuple fig = ax.get_figure() ## x,y of bottom left corner, width,height in percentage of figure size ## matches the default aspect ratio of matplotlib cur_size = fig.get_size_inches() * fig.dpi bbox = ax.get_position() extents = bbox.extents offset = 10 if span_full_figure: for ax in fig.get_axes(): bbox = ax.get_position() these_extents = bbox.extents for i in range(2): if these_extents[i] < extents[i]: extents[i] = these_extents[i] for i in range(2, 4): if these_extents[i] > extents[i]: extents[i] = these_extents[i] height = extents[3] - extents[1] width = extents[2] - extents[0] else: height = bbox.height width = bbox.width fig_x0, fig_y0, fig_x1, fig_y1 = extents if not horizontal: thickness = 20. / cur_size[0] * fig.dpi / 100 ax1 = fig.add_axes( [fig_x1 + offset / cur_size[0], fig_y0, thickness, height]) else: xlabel = ax.xaxis.get_label() if xlabel.get_text() != '': print( "addColorbar does not support finding xaxis text, this will look bad" ) thickness = 15. / cur_size[1] * fig.dpi / 100 ax1 = fig.add_axes([ fig_x0, fig_y0 - thickness - offset / cur_size[1], width, thickness ]) if type(cmap) == str: cmap = plt.get_cmap(cmap) cb1 = matplotlib.colorbar.ColorbarBase( ax1, cmap=cmap, extend='both', extendfrac=0.05, norm=norm(vmin=vmin, vmax=vmax), orientation='vertical' if not horizontal else 'horizontal') cb1.set_label(label, fontsize=fontsize) cb1.set_ticks(ticks) if tick_labels is not None: cb1.set_ticklabels(tick_labels) cb1.ax.tick_params(labelsize=fontsize) return cb1, ax1