def createAlignmentPlot(meanX, meanY): """ Create a plotter with the cumulative shift per frame. """ figureSize = (8, 6) plotter = Plotter(*figureSize) figure = plotter.getFigure() ax = figure.add_subplot(111) ax.grid() ax.axis('equal') ax.set_title('Cartesian representation') ax.set_xlabel('Drift x (pixels)') ax.set_ylabel('Drift y (pixels)') # Max range of the plot of the two coordinates plotRange = max(max(meanX) - min(meanX), max(meanY) - min(meanY)) i = 1 skipLabels = ceil(len(meanX) / 10.0) for x, y in izip(meanX, meanY): if i % skipLabels == 0: ax.text(x - 0.02 * plotRange, y + 0.02 * plotRange, str(i)) i += 1 ax.plot(meanX, meanY, color='b') ax.plot(meanX, meanY, 'yo') # setting the plot windows to properly see the data ax.axis([min(meanX) - 0.1 * plotRange, max(meanX) + 0.1 * plotRange, min(meanY) - 0.1 * plotRange, max(meanY) + 0.1 * plotRange]) plotter.tightLayout() return plotter
def movieCreatePlot(mic, saveFig): import xmipp meanX = [] meanY = [] figureSize = (8, 6) #alignedMovie = mic.alignMetaData md = xmipp.MetaData(mic.alignMetaData) plotter = Plotter(*figureSize) figure = plotter.getFigure() preX = 0.0 preY = 0.0 meanX.append(0.0) meanY.append(0.0) ax = figure.add_subplot(111) ax.grid() ax.set_title('Cartesian representation') ax.set_xlabel('Drift x (pixels)') ax.set_ylabel('Drift y (pixels)') ax.plot(0, 0, 'yo-') for objId in md: preX += md.getValue(xmipp.MDL_OPTICALFLOW_MEANX, objId) preY += md.getValue(xmipp.MDL_OPTICALFLOW_MEANY, objId) meanX.append(preX) meanY.append(preY) ax.plot(preX, preY, 'yo-') ax.text(preX-0.02, preY+0.01, str(objId+1)) ax.plot(np.asarray(meanX), np.asarray(meanY)) if saveFig: plotter.savefig(mic.plotCart) return plotter
def createGlobalAlignmentPlot(meanX, meanY, first): """ Create a plotter with the shift per frame. """ figureSize = (6, 4) plotter = Plotter(*figureSize) figure = plotter.getFigure() ax = figure.add_subplot(111) ax.grid() ax.set_title('Global shift') ax.set_xlabel('Shift x (pixels)') ax.set_ylabel('Shift y (pixels)') i = first skipLabels = ceil(len(meanX) / 10.0) labelTick = 1 for x, y in izip(meanX, meanY): if labelTick == 1: ax.text(x - 0.02, y + 0.02, str(i)) labelTick = skipLabels else: labelTick -= 1 i += 1 ax.plot(meanX, meanY, color='b') ax.plot(meanX, meanY, 'yo') plotter.tightLayout() return plotter
def plotFile(dbName, dbPreffix, plotType, columnsStr, colorsStr, linesStr, markersStr, xcolumn, ylabel, xlabel, title, bins, orderColumn, orderDirection): columns = columnsStr.split() colors = colorsStr.split() lines = linesStr.split() markers = markersStr.split() data = PlotData(dbName, dbPreffix, orderColumn, orderDirection) #setObj = getSetObject(dbName, dbPreffix) plotter = Plotter(windowTitle=title) ax = plotter.createSubPlot(title, xlabel, ylabel) xvalues = data.getColumnValues(xcolumn) if xcolumn else range(0, data.getSize()) #xvalues = range(0, setObj.getSize()) if not isxvalues else [] for i, col in enumerate(columns): yvalues = data.getColumnValues(col) color = colors[i] line = lines[i] if bins: ax.hist(yvalues, bins=int(bins), color=color, linestyle=line, label=col) else: if plotType == 'Plot': marker = (markers[i] if not markers[i] == 'none' else None) ax.plot(xvalues, yvalues, color, marker=marker, linestyle=line, label=col) else: ax.scatter(xvalues, yvalues, c=color, label=col, alpha=0.5) ax.legend(columns) return plotter
def _showBFactorPlot(self, key): if key == 'guinier': label = 'rlnFittedInterceptGuinierPlot' title = "Polishing scale-factors" else: # bfactor label = 'rlnBfactorUsedForSharpening' title = "Polishing B-factors" modelStar = self.protocol._getFileName('bfactors') if os.path.exists(modelStar): table = Table(fileName=modelStar, tableName='perframe_bfactors') frame = table.getColumnValues('rlnMovieFrameNumber') bfactor = map(float, table.getColumnValues(label)) plotter = Plotter() figure = plotter.getFigure() a = figure.add_subplot(111) a.grid(True) a.set_xlabel('Movie frame number') a.set_ylabel(label) a.invert_yaxis() a.plot(frame, list(bfactor)) a.set_title(title) plotter.tightLayout() return [plotter]
def createFromFile(cls, dbName, dbPreffix, plotType, columnsStr, colorsStr, linesStr, markersStr, xcolumn, ylabel, xlabel, title, bins, orderColumn, orderDirection): columns = columnsStr.split() colors = colorsStr.split() lines = linesStr.split() markers = markersStr.split() data = PlotData(dbName, dbPreffix, orderColumn, orderDirection) plotter = Plotter(windowTitle=title) ax = plotter.createSubPlot(title, xlabel, ylabel) xvalues = data.getColumnValues(xcolumn) if xcolumn else range(0, data.getSize()) for i, col in enumerate(columns): yvalues = data.getColumnValues(col) color = colors[i] line = lines[i] colLabel = col if not col.startswith("_") else col[1:] if bins: yvalues = data._removeInfinites(yvalues) ax.hist(yvalues, bins=int(bins), color=color, linestyle=line, label=colLabel) else: if plotType == 'Plot': marker = (markers[i] if not markers[i] == 'none' else None) ax.plot(xvalues, yvalues, color, marker=marker, linestyle=line, label=colLabel) else: ax.scatter(xvalues, yvalues, c=color, label=col, alpha=0.5) ax.legend() return plotter
def movieCreatePlot(mic, saveFig): import xmipp meanX = [] meanY = [] figureSize = (8, 6) #alignedMovie = mic.alignMetaData md = xmipp.MetaData(mic.alignMetaData) plotter = Plotter(*figureSize) figure = plotter.getFigure() preX = 0.0 preY = 0.0 meanX.append(0.0) meanY.append(0.0) ax = figure.add_subplot(111) ax.grid() ax.set_title('Cartesian representation') ax.set_xlabel('Drift x (pixels)') ax.set_ylabel('Drift y (pixels)') ax.plot(0, 0, 'yo-') for objId in md: preX += md.getValue(xmipp.MDL_OPTICALFLOW_MEANX, objId) preY += md.getValue(xmipp.MDL_OPTICALFLOW_MEANY, objId) meanX.append(preX) meanY.append(preY) ax.plot(preX, preY, 'yo-') ax.text(preX - 0.02, preY + 0.01, str(objId + 1)) ax.plot(np.asarray(meanX), np.asarray(meanY)) if saveFig: plotter.savefig(mic.plotCart) return plotter
def createGlobalAlignmentPlot(meanX, meanY, first): """ Create a plotter with the cumulative shift per frame. """ sumMeanX = [] sumMeanY = [] preX = 0.0 preY = 0.0 figureSize = (6, 4) plotter = Plotter(*figureSize) figure = plotter.getFigure() ax = figure.add_subplot(111) ax.grid() ax.set_title('Global frame shift (cumulative)') ax.set_xlabel('Shift x (pixels)') ax.set_ylabel('Shift y (pixels)') if meanX[0] != 0 or meanY[0] != 0: raise Exception("First frame shift must be (0,0)!") i = first for x, y in izip(meanX, meanY): preX += x preY += y sumMeanX.append(preX) sumMeanY.append(preY) ax.text(preX - 0.02, preY + 0.02, str(i)) i += 1 ax.plot(sumMeanX, sumMeanY, color='b') ax.plot(sumMeanX, sumMeanY, 'yo') plotter.tightLayout() return plotter
def createAlignmentPlot(meanX, meanY): """ Create a plotter with the cumulative shift per frame. """ sumMeanX = [] sumMeanY = [] figureSize = (8, 6) plotter = Plotter(*figureSize) figure = plotter.getFigure() preX = 0.0 preY = 0.0 sumMeanX.append(0.0) sumMeanY.append(0.0) ax = figure.add_subplot(111) ax.grid() ax.set_title('Cartesian representation') ax.set_xlabel('Drift x (pixels)') ax.set_ylabel('Drift y (pixels)') ax.plot(0, 0, 'yo-') i = 1 for x, y in izip(meanX, meanY): preX += x preY += y sumMeanX.append(preX) sumMeanY.append(preY) #ax.plot(preX, preY, 'yo-') ax.text(preX-0.02, preY+0.02, str(i)) i += 1 ax.plot(sumMeanX, sumMeanY, color='b') ax.plot(sumMeanX, sumMeanY, 'yo') plotter.tightLayout() return plotter
def createGlobalAlignmentPlot(meanX, meanY, first, pixSize): """ Create a plotter with the shift per frame. """ sumMeanX = [] sumMeanY = [] def px_to_ang(px): y1, y2 = px.get_ylim() x1, x2 = px.get_xlim() ax_ang2.set_ylim(y1 * pixSize, y2 * pixSize) ax_ang.set_xlim(x1 * pixSize, x2 * pixSize) ax_ang.figure.canvas.draw() ax_ang2.figure.canvas.draw() figureSize = (6, 4) plotter = Plotter(*figureSize) figure = plotter.getFigure() ax_px = figure.add_subplot(111) ax_px.grid() ax_px.set_xlabel('Shift x (px)') ax_px.set_ylabel('Shift y (px)') ax_ang = ax_px.twiny() ax_ang.set_xlabel('Shift x (A)') ax_ang2 = ax_px.twinx() ax_ang2.set_ylabel('Shift y (A)') i = first # The output and log files list the shifts relative to the first frame. # ROB unit seems to be pixels since sampling rate is only asked # by the program if dose filtering is required skipLabels = ceil(len(meanX) / 10.0) labelTick = 1 for x, y in zip(meanX, meanY): sumMeanX.append(x) sumMeanY.append(y) if labelTick == 1: ax_px.text(x - 0.02, y + 0.02, str(i)) labelTick = skipLabels else: labelTick -= 1 i += 1 # automatically update lim of ax_ang when lim of ax_px changes. ax_px.callbacks.connect("ylim_changed", px_to_ang) ax_px.callbacks.connect("xlim_changed", px_to_ang) ax_px.plot(sumMeanX, sumMeanY, color='b') ax_px.plot(sumMeanX, sumMeanY, 'yo') ax_px.plot(sumMeanX[0], sumMeanY[0], 'ro', markersize=10, linewidth=0.5) ax_px.set_title('Global frame alignment') plotter.tightLayout() return plotter
def createGlobalAlignmentPlot(meanX, meanY, first, pixSize): """ Create a plotter with the shift per frame. """ sumMeanX = [] sumMeanY = [] def px_to_ang(ax_px): y1, y2 = ax_px.get_ylim() x1, x2 = ax_px.get_xlim() ax_ang2.set_ylim(y1 * pixSize, y2 * pixSize) ax_ang.set_xlim(x1 * pixSize, x2 * pixSize) ax_ang.figure.canvas.draw() ax_ang2.figure.canvas.draw() figureSize = (6, 4) plotter = Plotter(*figureSize) figure = plotter.getFigure() ax_px = figure.add_subplot(111) ax_px.grid() ax_px.set_xlabel('Shift x (px)') ax_px.set_ylabel('Shift y (px)') ax_ang = ax_px.twiny() ax_ang.set_xlabel('Shift x (A)') ax_ang2 = ax_px.twinx() ax_ang2.set_ylabel('Shift y (A)') i = first # The output _rlnMicrographShiftX/Y shifts relative to the first frame. # Unit is pixels of the original (unbinned) movies (Takanori, 2018) skipLabels = ceil(len(meanX) / 10.0) labelTick = 1 for x, y in zip(meanX, meanY): sumMeanX.append(x) sumMeanY.append(y) if labelTick == 1: ax_px.text(x - 0.02, y + 0.02, str(i)) labelTick = skipLabels else: labelTick -= 1 i += 1 # automatically update lim of ax_ang when lim of ax_px changes. ax_px.callbacks.connect("ylim_changed", px_to_ang) ax_px.callbacks.connect("xlim_changed", px_to_ang) ax_px.plot(sumMeanX, sumMeanY, color='b') ax_px.plot(sumMeanX, sumMeanY, 'yo') ax_px.plot(sumMeanX[0], sumMeanY[0], 'ro', markersize=10, linewidth=0.5) ax_px.set_title('Global frame alignment') plotter.tightLayout() return plotter
def savePlots(self, results=None): """ Store png images of the plots to be used as images, """ # Add resmap libraries to the path sys.path.append(os.environ['RESMAP_HOME']) # This is needed right now because we are having # some memory problem with matplotlib plots right now in web Plotter.setBackend('Agg') self._plotVolumeSlices().savefig(self._getExtraPath('volume1.map.png')) plot = self._plotResMapSlices(results['resTOTALma']) plot.savefig(self._getExtraPath('volume1_resmap.map.png')) self._plotHistogram().savefig(self._getExtraPath('histogram.png'))
def _runPreWhiteningWeb(protocol, results): newAng = protocol.prewhitenAng.get() newRamp = protocol.prewhitenRamp.get() figsize = (18, 9) gridsize = [0, 0] plotter = Plotter(*gridsize, figsize=figsize, windowTitle="ResMap") myCreatePrewhiteningFigure(results, plotter.getFigure(), newAng, newRamp) return plotter
def createGlobalAlignmentPlot(meanX, meanY, first): """ Create a plotter with the shift per frame. """ sumMeanX = [] sumMeanY = [] preX = 0.0 preY = 0.0 figureSize = (6, 4) plotter = Plotter(*figureSize) figure = plotter.getFigure() ax = figure.add_subplot(111) ax.grid() ax.set_title('Alignment based upon full frames') ax.set_xlabel('Shift x (pixels)') ax.set_ylabel('Shift y (pixels)') # morioncor2 (1.0.2) values refer to the middle frame, so first frame is no longer 0,0 #if meanX[0] != 0 or meanY[0] != 0: # raise Exception("First frame shift must be (0,0)!") i = first # ROB no accumulation is needed # see Motioncor2 user manual: "The output and log files list the shifts relative to the first frame." # or middle frame for motioncor2 1.0.2 # ROB unit seems to be pixels since samplingrate is only asked by the program if # dose filtering is required skipLabels = ceil(len(meanX) / 10.0) labelTick = 1 for x, y in izip(meanX, meanY): #preX += x #preY += y preX = x preY = y sumMeanX.append(preX) sumMeanY.append(preY) if labelTick == 1: ax.text(preX - 0.02, preY + 0.02, str(i)) labelTick = skipLabels else: labelTick -= 1 i += 1 ax.plot(sumMeanX, sumMeanY, color='b') ax.plot(sumMeanX, sumMeanY, 'yo') plotter.tightLayout() return plotter
def _plotGrid(self, grid, x, y): plotter = Plotter(windowTitle="Acquisitions for grid %s" % grid) plt = plotter.createSubPlot("Locations", "X", "Y") plt.axis('scaled') plt.autoscale(tight=True) self.loadAtlasImg(plt, grid) colors = ["cyan"] * len(x) area = np.pi * 3 plotter.scatterP(x, y, s=area, c=colors, edgecolors='none', alpha=1) return plotter
def _runPreWhiteningWeb(protocol, results): newAng = protocol.prewhitenAng.get() newRamp = protocol.prewhitenRamp.get() figsize = (18, 9) gridsize = [0, 0] plotter = Plotter(*gridsize, figsize=figsize, windowTitle="ResMap") myCreatePrewhiteningFigure(results, plotter.getFigure(), newAng, newRamp ) return plotter
def createGlobalAlignmentPlot(meanX, meanY, first): """ Create a plotter with the shift per frame. """ sumMeanX = [] sumMeanY = [] preX = 0.0 preY = 0.0 figureSize = (6, 4) plotter = Plotter(*figureSize) figure = plotter.getFigure() ax = figure.add_subplot(111) ax.grid() ax.set_title('Alignment based upon full frames') ax.set_xlabel('Shift x (pixels)') ax.set_ylabel('Shift y (pixels)') # motioncor2 (1.0.2) values refer to the middle frame, so first frame is no longer 0,0 #if meanX[0] != 0 or meanY[0] != 0: # raise Exception("First frame shift must be (0,0)!") i = first # ROB no accumulation is needed # see Motioncor2 user manual: "The output and log files list the shifts relative to the first frame." # or middle frame for motioncor2 1.0.2 # ROB unit seems to be pixels since samplingrate is only asked by the program if # dose filtering is required skipLabels = ceil(len(meanX)/10.0) labelTick = 1 for x, y in izip(meanX, meanY): #preX += x #preY += y preX = x preY = y sumMeanX.append(preX) sumMeanY.append(preY) if labelTick == 1: ax.text(preX - 0.02, preY + 0.02, str(i)) labelTick = skipLabels else: labelTick -= 1 i += 1 ax.plot(sumMeanX, sumMeanY, color='b') ax.plot(sumMeanX, sumMeanY, 'yo') plotter.tightLayout() return plotter
def _plotHistogram(self, param=None): md = MetaData() md.read(self.protocol._getFileName(FN_METADATA_HISTOGRAM)) x_axis = [] y_axis = [] i = 0 for idx in md: x_axis_ = md.getValue(MDL_X, idx) if i == 0: x0 = x_axis_ elif i == 1: x1 = x_axis_ y_axis_ = md.getValue(MDL_COUNT, idx) i += 1 x_axis.append(x_axis_) y_axis.append(y_axis_) delta = x1 - x0 fig = plt.figure() plt.bar(x_axis, y_axis, width=delta) plt.title("Resolutions Histogram") plt.xlabel("Resolution (A)") plt.ylabel("Counts") return [Plotter(figure2=fig)]
def createPlot2D(self, volPrefix, md): import xmipp figurePath = self._getExtraPath(volPrefix + 'softAlignmentValidation2D.png') figureSize = (8, 6) #alignedMovie = mic.alignMetaData plotter = Plotter(*figureSize) figure = plotter.getFigure() ax = figure.add_subplot(111) ax.grid() ax.set_title('Soft alignment validation map') ax.set_xlabel('Angular Precision') ax.set_ylabel('Angular Accuracy') for objId in md: x = md.getValue(xmipp.MDL_SCORE_BY_ALIGNABILITY_PRECISION, objId) y = md.getValue(xmipp.MDL_SCORE_BY_ALIGNABILITY_ACCURACY, objId) ax.plot(x, y, 'r.', markersize=1) ax.grid(True, which='both') ax.autoscale_view(True, True, True) plotter.savefig(figurePath) plotter.show() return plotter
def _plotResMapSlices(self, data=None, **kwargs): from ResMap_visualization import plotResMapVolume plotDict = loads(self.plotData.get()) if data is None: data = self._getVolumeMatrix('volume1_resmap.map') data = np.ma.masked_where(data > plotDict['currentRes'], data, copy=True) kwargs.update(plotDict) fig = plotResMapVolume(data, **kwargs) return Plotter(figure=fig)
def _createSpectraPlot(self, label, array, index, objId=None): if objId is None: objId = index # Number of harmonics calculated plotter = Plotter() a = plotter.createSubPlot('Spectrum for %s %d' % (label, objId), xlabel='Harmonics', ylabel='Energy') n = self.spectraHighHarmonic.get() - self.spectraLowHarmonic.get() + 1 i1 = (index-1) * n i2 = i1 + n xdata = range(self.spectraLowHarmonic.get(), self.spectraHighHarmonic.get()+1) ydata = array[i1:i2] a.plot(xdata, ydata) plotFile = join(self.plotsDir, 'spectra_%s%06d.png' % (label, objId)) plotter.savefig(plotFile) return plotFile
def main(): parser = argparse.ArgumentParser(prog='Scipion Plot') parser.add_argument('--file', help='File to visualize', required=True) parser.add_argument('--block', help='Block to visualize') parser.add_argument('--type', help='Plot type') parser.add_argument('--columns', help='Columns to plot') parser.add_argument('--xcolumn', help='X Column to plot') parser.add_argument('--orderColumn', help='Column to order') parser.add_argument('--orderDir', help='Order direction(ASC, DESC)') parser.add_argument('--bins', help='If plot type is histogram, number of bins') parser.add_argument('--colors', help='Colors to plot columns') parser.add_argument('--styles', help='Styles to plot columns') parser.add_argument('--markers', help='Markers to plot columns') parser.add_argument('--title', help='Plot title', default='') parser.add_argument('--ytitle', help='Y axis title', default='') parser.add_argument('--xtitle', help='X axis title', default='') args = parser.parse_args() plotfile = args.file block = args.block if args.block else '' type = args.type columns = args.columns xcolumn = args.xcolumn orderColumn = args.orderColumn orderDir = args.orderDir bins = args.bins colors = args.colors styles = args.styles markers = args.markers title = args.title xtitle = args.xtitle ytitle = args.ytitle Plotter.setBackend('TkAgg') plotter = EmPlotter.createFromFile(plotfile, block, type, columns, colors, styles, markers, xcolumn, ytitle, xtitle, title, bins, orderColumn, orderDir) plotter.show(block=True)
def main(): parser = argparse.ArgumentParser(prog='Scipion Plot') parser.add_argument('--file', help='File to visualize', required=True) parser.add_argument('--block', help='Block to visualize') parser.add_argument('--type', help='Plot type') parser.add_argument('--columns', help='Columns to plot') parser.add_argument('--xcolumn', help='X Column to plot') parser.add_argument('--orderColumn', help='Column to order') parser.add_argument('--orderDir', help='Order direction(ASC, DESC)') parser.add_argument('--bins', help='If plot type is histogram, number of bins') parser.add_argument('--colors', help='Colors to plot columns') parser.add_argument('--styles', help='Styles to plot columns') parser.add_argument('--markers', help='Markers to plot columns') parser.add_argument('--title', help='Plot title', default='') parser.add_argument('--ytitle', help='Y axis title', default='') parser.add_argument('--xtitle', help='X axis title', default='') args = parser.parse_args() #print args plotfile = args.file block = args.block if args.block else '' type = args.type columns = args.columns xcolumn = args.xcolumn orderColumn = args.orderColumn orderDir = args.orderDir bins = args.bins colors = args.colors styles = args.styles markers = args.markers title = args.title xtitle = args.xtitle ytitle = args.ytitle Plotter.setBackend('TkAgg') plotFile(plotfile, block, type, columns, colors, styles, markers, xcolumn, ytitle, xtitle, title, bins, orderColumn, orderDir).show(block=True)
def createPlot2D(self,volPrefix,md): import xmipp figurePath = self._getExtraPath(volPrefix + 'softAlignmentValidation2D.png') figureSize = (8, 6) #alignedMovie = mic.alignMetaData plotter = Plotter(*figureSize) figure = plotter.getFigure() ax = figure.add_subplot(111) ax.grid() ax.set_title('Soft alignment validation map') ax.set_xlabel('Angular Precision') ax.set_ylabel('Angular Accuracy') for objId in md: x = md.getValue(xmipp.MDL_SCORE_BY_ALIGNABILITY_PRECISION, objId) y = md.getValue(xmipp.MDL_SCORE_BY_ALIGNABILITY_ACCURACY, objId) ax.plot(x, y, 'r.',markersize=1) ax.grid(True, which='both') ax.autoscale_view(True,True,True) plotter.savefig(figurePath) plotter.show() return plotter
def visualize(self, obj, **args): cls = type(obj) if issubclass(cls, AtsasProtConvertPdbToSAXS): if obj.experimentalSAXS.empty(): fnInt=obj._getPath("pseudoatoms00.int") else: fnInt=obj._getPath("pseudoatoms00.fit") import numpy x=numpy.loadtxt(fnInt,skiprows=1) xplotter = Plotter(windowTitle="SAXS Curves") a = xplotter.createSubPlot('SAXS curves', 'Angstrongs^-1', 'log(SAXS)', yformat=False) a.plot(x[:,0], numpy.log(x[:,1])) a.plot(x[:,0], numpy.log(x[:,2])) if obj.experimentalSAXS.empty(): xplotter.showLegend(['SAXS in solution','SAXS in vacuo']) else: xplotter.showLegend(['Experimental SAXS','SAXS from volume']) xplotter.show()
def createGlobalAlignmentPlot(meanX, meanY, first): """ Create a plotter with the shift per frame. """ sumMeanX = [] sumMeanY = [] preX = 0.0 preY = 0.0 figureSize = (6, 4) plotter = Plotter(*figureSize) figure = plotter.getFigure() ax = figure.add_subplot(111) ax.grid() ax.set_title('Alignment based upon full frames') ax.set_xlabel('Shift x (pixels)') ax.set_ylabel('Shift y (pixels)') i = first skipLabels = ceil(len(meanX)/10.0) labelTick = 1 for x, y in izip(meanX, meanY): preX = x preY = y sumMeanX.append(preX) sumMeanY.append(preY) if labelTick == 1: ax.text(preX - 0.02, preY + 0.02, str(i)) labelTick = skipLabels else: labelTick -= 1 i += 1 ax.plot(sumMeanX, sumMeanY, color='b') ax.plot(sumMeanX, sumMeanY, 'yo') plotter.tightLayout() return plotter
def getTestPlot(request): """ Just a test of a custom render function. """ from pyworkflow.gui.plotter import Plotter xplotter = Plotter() xplotter.createSubPlot("Particle sorting", "Particle number", "Zscore") x = range(100) xplotter.plot(x) canvas = xplotter.getCanvas() response = HttpResponse(content_type='image/png') canvas.print_png(response) return response
def _visualizeLLPlot(self, e=None): """ Plot -LL vs cycle :N:1,5: """ headerList, dataList, msg, title = self.parseFile.retrievemLLPlot() if not dataList: errorWindow(self.getTkRoot(), msg) return xplotter = Plotter(windowTitle=title) a = xplotter.createSubPlot(title, headerList[0], '-LL', yformat=False) # see # https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.plot.html a.plot(dataList[0], dataList[1], 'bx-') xplotter.showLegend(headerList[1:]) xplotter.show()
def _visualizeRFactorPlot(self, e=None): """ Plot Rfactor and Rfree vs cycle :N:[1,3]: """ headerList, dataList, msg, title = self.parseFile.retrieveRFactorPlot() if not dataList: errorWindow(self.getTkRoot(), msg) return xplotter = Plotter(windowTitle=title) a = xplotter.createSubPlot(title, headerList[0], 'Rfactor', yformat=False) # see # https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.plot.html # for plot options a.plot(dataList[0], dataList[1], 'bx-', dataList[0], dataList[2], 'gx-') # plot start over line in blue xplotter.showLegend(headerList[1:]) xplotter.show()
def _visualizeGeometryPlot(self, e=None): """ Plot rmsBOND,zBOND, rmsANGL, zANGL and rmsCHIRALvs cycle : N:1,7,8,9,10,11: """ headerList, dataList, msg, title = \ self.parseFile.retrieveGeometryPlot() if not dataList: errorWindow(self.getTkRoot(), msg) return xplotter = Plotter(windowTitle=title) a = xplotter.createSubPlot(title, headerList[0], 'geometry', yformat=False) # see # https://matplotlib.org/api/_as_gen/matplotlib.axes.Axes.plot.html # for plot options a.plot( dataList[0], dataList[1], 'bx-', dataList[0], dataList[2], 'gx-', dataList[0], dataList[3], 'rx-', dataList[0], dataList[4], 'cx-', dataList[0], dataList[5], 'mx-', ) # plot start over line in blue xplotter.showLegend(headerList[1:]) xplotter.show()
def _plotHistogram(self): from ResMap_visualization import plotResolutionHistogram histogramData = loads(self.histogramData.get()) fig = plotResolutionHistogram(histogramData) return Plotter(figure=fig)
def __init__(self, path, master=None): # Load global configuration self.projName = os.path.basename(path) try: projTitle = '%s (%s on %s)' % (self.projName, pwutils.getLocalUserName(), pwutils.getLocalHostName()) except Exception: projTitle = self.projName self.projPath = path self.loadProject() # TODO: put the menu part more nicely. From here: menu = MenuConfig() projMenu = menu.addSubMenu('Project') projMenu.addSubMenu('Browse files', 'browse', icon='fa-folder-open.png') projMenu.addSubMenu('Remove temporary files', 'delete', icon='fa-trash-o.png') projMenu.addSubMenu('Manage project labels', 'labels', icon=Icon.TAGS) projMenu.addSubMenu('Toogle color mode', 'color_mode', shortCut="Ctrl+t", icon=Icon.ACTION_VISUALIZE) projMenu.addSubMenu('Select all protocols', 'select all', shortCut="Ctrl+a") projMenu.addSubMenu('Find protocol to add', 'find protocol', shortCut="Ctrl+f") projMenu.addSubMenu('', '') # add separator projMenu.addSubMenu('Import workflow', 'load_workflow', icon='fa-download.png') projMenu.addSubMenu('Search workflow', 'search_workflow', icon = 'fa-search.png') projMenu.addSubMenu('Export tree graph', 'export_tree') projMenu.addSubMenu('', '') # add separator projMenu.addSubMenu('Notes', 'notes', icon='fa-pencil.png') projMenu.addSubMenu('', '') # add separator projMenu.addSubMenu('Exit', 'exit', icon='fa-sign-out.png') helpMenu = menu.addSubMenu('Help') helpMenu.addSubMenu('Online help', 'online_help', icon='fa-external-link.png') helpMenu.addSubMenu('About', 'about', icon='fa-question-circle.png') helpMenu.addSubMenu('Contact support', 'contact_us', icon='fa-question-circle.png') self.menuCfg = menu # TODO: up to here if self.project.openedAsReadOnly(): self.projName += "<READ ONLY>" # Notify about the workflow in this project self.icon = self.generalCfg.icon.get() self.selectedProtocol = None self.showGraph = False Plotter.setBackend('TkAgg') ProjectBaseWindow.__init__(self, projTitle, master, icon=self.icon, minsize=(90,50)) self.root.attributes("-zoomed", True) self.switchView(VIEW_PROTOCOLS) self.initProjectTCPServer() # Socket thread to communicate with clients ProjectWorkflowNotifier(self.project).notifyWorkflow()
def _plotVolumeSlices(self, **kwargs): from ResMap_visualization import plotOriginalVolume fig = plotOriginalVolume(self._getVolumeMatrix('volume1.map'), **kwargs) return Plotter(figure=fig)
def __init__(self, x=1, y=1, mainTitle="", **kwargs): Plotter.__init__(self, x, y, mainTitle, **kwargs)
def movieCreatePlot(plotType, movie, saveFig): import xmipp meanX = [] meanY = [] stdX = [] stdY = [] colors = [] gr = 255.0 # if movie is None: # return [self.errorMessage("Invalid movie id *%d*" % movieId, # title="Invalid input")] alignedMovie = movie.alignMetaData md = xmipp.MetaData(alignedMovie) colorDist = 255 / md.size() cartPosition = None polarPosition = None colorBarPosition = 122 figureSize = (8, 6) if plotType == PLOT_CART: cartPosition = 121 elif plotType == PLOT_POLAR: polarPosition = 121 elif plotType == PLOT_POLARCART: cartPosition = 132 polarPosition = 131 colorBarPosition = 133 plotter = Plotter(*figureSize) figure = plotter.getFigure() # Plot the color bar ax = figure.add_subplot(colorBarPosition, aspect="equal", xlim=[0, 6]) ax.set_xticklabels([]) ax.set_yticklabels([]) colorBarX = np.array([1, 1]) colorBarY = np.array([2, 4]) # Read the shifts information from the Metadata for objId in md: meanX.append(md.getValue(xmipp.MDL_OPTICALFLOW_MEANX, objId)) meanY.append(md.getValue(xmipp.MDL_OPTICALFLOW_MEANY, objId)) stdX.append(md.getValue(xmipp.MDL_OPTICALFLOW_STDY, objId)) stdY.append(md.getValue(xmipp.MDL_OPTICALFLOW_STDY, objId)) colors.append((1, gr / 255.0, 0)) ax.plot(colorBarX, colorBarY, c=(1, gr / 255.0, 0), linewidth=10) ax.text(2, np.mean(colorBarY), str(objId) + "-" + str(objId + 1)) colorBarY += 2 gr -= colorDist area = (np.sqrt(np.power(np.asarray(stdX), 2) + np.power(np.asarray(stdY), 2))) * 700 # Plot in polar if needed if polarPosition: r = np.sqrt(np.power(np.asarray(meanX), 2) + np.power(np.asarray(meanY), 2)) theta = np.arctan2(meanY, meanX) * 180 / np.pi ax = figure.add_subplot(polarPosition, projection="polar") ax.set_title("Polar representation") c = ax.scatter(theta, r, c=colors, s=area, cmap=plt.cm.hsv) c.set_alpha(0.75) ax.plot(theta, r, "-^") if saveFig: plotter.savefig(movie.plotPolar) # Plot in cartesian if needed if cartPosition: ax = figure.add_subplot(cartPosition) ax.grid() ax.grid() ax.set_title("Cartesian representation") c = ax.scatter(np.asarray(meanX), np.asarray(meanY), c=colors, s=area, cmap=plt.cm.hsv) c.set_alpha(0.75) ax.plot(np.asarray(meanX), np.asarray(meanY), "-^") if saveFig: plotter.savefig(movie.plotCart) return plotter
def __init__(self, path, master=None): # Load global configuration self.projName = os.path.basename(path) try: projTitle = '%s (%s on %s)' % (self.projName, pwutils.getLocalUserName(), pwutils.getLocalHostName()) except Exception: projTitle = self.projName self.projPath = path self.project = self.loadProject() # TODO: put the menu part more nicely. From here: menu = MenuConfig() projMenu = menu.addSubMenu('Project') projMenu.addSubMenu('Browse files', 'browse', icon='fa-folder-open.gif') projMenu.addSubMenu('Remove temporary files', 'delete', icon='fa-trash-o.gif') projMenu.addSubMenu('Manage project labels', 'labels', icon=Icon.TAGS) projMenu.addSubMenu('Toggle color mode', 'color_mode', shortCut="Ctrl+t", icon=Icon.ACTION_VISUALIZE) projMenu.addSubMenu('Select all protocols', 'select all', shortCut="Ctrl+a") projMenu.addSubMenu('Find protocol to add', 'find protocol', shortCut="Ctrl+f") projMenu.addSubMenu('', '') # add separator projMenu.addSubMenu('Import workflow', 'load_workflow', icon='fa-download.gif') projMenu.addSubMenu('Search workflow', 'search_workflow', icon='fa-search.gif') if pw.Config.debugOn(): projMenu.addSubMenu('Export tree graph', 'export_tree') projMenu.addSubMenu('', '') # add separator projMenu.addSubMenu('Debug Mode', 'debug mode', shortCut="Ctrl+d", icon='debug.gif') projMenu.addSubMenu('', '') # add separator projMenu.addSubMenu('Notes', 'notes', icon='fa-pencil.gif') projMenu.addSubMenu('', '') # add separator projMenu.addSubMenu('Exit', 'exit', icon='fa-sign-out.gif') helpMenu = menu.addSubMenu('Help') helpMenu.addSubMenu('Online help', 'online_help', icon='fa-external-link.gif') helpMenu.addSubMenu('About', 'about', icon='fa-question-circle.gif') helpMenu.addSubMenu('Contact support', 'contact_us', icon='fa-question-circle.gif') self.menuCfg = menu if self.project.openedAsReadOnly(): self.projName += "<READ ONLY>" # Notify about the workflow in this project self.selectedProtocol = None self.showGraph = False Plotter.setBackend('TkAgg') ProjectBaseWindow.__init__(self, projTitle, master, minsize=(90, 50), icon=Icon.SCIPION_ICON_PROJ) OS.handler().maximizeWindow(self.root) self.switchView(VIEW_PROTOCOLS) self.initProjectTCPServer( ) # Socket thread to communicate with clients ProjectWorkflowNotifier(self.project).notifyWorkflow()