예제 #1
0
class PlotHandler(object):
    def __init__(self, parent):
        self.figure = Figure(tight_layout=True)
        self.canvas = FigureCanvas(self.figure)
        self.canvas.setContentsMargins(0,0,0,0)
        self.axes = self.figure.add_subplot(111, projection='3d')
        Axes3D.set_autoscale_on(self.axes, True)
        Axes3D.autoscale_view(self.axes)
        self.canvas.setParent(parent)
        self.activePlot = None
        self.activePopulation = None

        self.surface = None
        self.scatter = None

    def get_widget(self):
        return self.canvas

    def updatePlot(self, X, Y, Z, population=None):
        self.activePlot = (X,Y,Z)
        x, y = np.meshgrid(X,Y)

        if self.surface is not None:
            self.surface.remove()

        if self.scatter is not None:
            self.scatter.remove()

        # surface
        self.surface = Axes3D.plot_surface(
                self.axes,
                x, y, Z,
                rstride=1,
                cstride=1,
                cmap=cm.coolwarm,
                linewidth=0,
                antialiased=False,
                shade=False,
                alpha=0.5
        )

        # population
        if population is not None:
            self.activePopulation = population
            x, y, z = self.preparePopulationData(population)
            self.scatter = Axes3D.scatter(self.axes, x, y, z, c="r", marker="o")
            self.scatter.set_alpha(1.0)

        # Draw all
        self.canvas.draw()
        self.canvas.flush_events()

    def updatePopulation(self, population):
        self.activePopulation = population
        x, y, z = self.preparePopulationData(population)

        if self.scatter is not None:
            self.scatter.remove()

        self.scatter = Axes3D.scatter(self.axes, x, y, z, c="r", marker="o")
        # self.surface.set_zorder(2)
        # self.scatter.set_zorder(100)
        self.scatter.set_alpha(1.0)
        self.canvas.draw()
        self.canvas.flush_events()

    def preparePopulationData(self, population):
        x = []
        y = []
        z = []
        for p in population:
            # x.append(p.parameters[0])
            # y.append(p.parameters[1])
            # z.append(p.fitness)
            x.append(p[0])
            y.append(p[1])
            z.append(p[2]+0.1)
        return (x, y, z)
예제 #2
0
class PlotWidget(QtGui.QWidget):
    def __init__(self, title, parent=None):
        super(PlotWidget, self).__init__(parent) 

        self.title = title
        self.createPlotCanvases(title)
        
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.toolbar)
        layout.addWidget(self.canvas)
        self.setLayout(layout)

    def getTitle(self):
        return self.title

    def setXLabel(self, xlabel):
        self.plot.set_xlabel(xlabel,fontsize=8)
    
    def createPlotCanvases(self, title):
        # create figure instances to plot on
        figure = Figure(figsize=(5,4), dpi=100)
        
        self.plot = figure.add_subplot(111)
        self.plot.grid(True)
        self.plot.tick_params(axis='x', labelsize=6)
        self.plot.tick_params(axis='y', labelsize=6)

        figure.subplots_adjust(left=0.15, bottom=0.2, right=0.9, top=0.9, wspace=0.2, hspace=0.5)
        
        figure.suptitle(title, fontsize=8)
        # this is the Canvas Widget that displays the `figure`
        self.canvas = FigureCanvas(figure)
        self.canvas.setContentsMargins(110, 50, 50, 50)
        # this is the Navigation widget
        self.toolbar = NavigationToolbar(self.canvas, self)  

    def updateReset(self):
        self.plot.clear()
        self.plot.grid(True)
        self.canvas.draw()
    
    def simplePlot(self, x_axis, y_axis):
        self.plot.plot(x_axis, y_axis)
        self.canvas.draw()

    def updatePlot(self, array, dimSize, dimPos, dims,  x_axis, x_axis_idx, tixi, path, displayOpt):
        """update the plot window. 
        
        Args:
            tixi       (Tixi)   : to get the Array value
            path       (String) : path to aeroPerformanceMap
            
            x_axis_idx (int)    : index of the chosen x-axis (e.g. in for all list)
            x_axis     ([float]): x-axis float array

            array      ([float]): complete coefficent array (e.g. cfx)
            dimSize    ([int])  : e.g. dimSize = [cnt_mach, cnt_reyn, cnt_angleYaw, cnt_angleAtt, cnt_relDef]            
            dimPos     ([int])  : e.g. dimPos = [mach_idx, reyn_idx, yaw_idx, att_idx, relDef_idx]
            dims       (int)    : count of dimensions
            displayOpt (String) : option if plots line or point style 
        
        """        
        y_axis = []

        j = 0
        # iterate over all indices (len) of x-axis
        while j < dimSize[x_axis_idx]:
            # set the indices for the searched value in dimPos
            # four of the five indices are fixed by selection
            # the fifth value is specified by every index of the chosen x-axis
            dimPos[x_axis_idx] = j
            y_axis.append(tixi.getArrayValue(array, dimSize, dimPos, dims))            
            
            j += 1
       
        print (x_axis)
        print (y_axis)
       
        self.plot.plot(x_axis, y_axis, displayOpt)
        self.canvas.draw()