Beispiel #1
0
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   
Beispiel #2
0
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
Beispiel #3
0
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
Beispiel #4
0
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
Beispiel #5
0
    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
Beispiel #6
0
    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 _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()
Beispiel #8
0
 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 _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
Beispiel #10
0
 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 _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()