当前位置: 首页>>代码示例>>Python>>正文


Python FigureCanvasQTAgg.setContentsMargins方法代码示例

本文整理汇总了Python中matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg.setContentsMargins方法的典型用法代码示例。如果您正苦于以下问题:Python FigureCanvasQTAgg.setContentsMargins方法的具体用法?Python FigureCanvasQTAgg.setContentsMargins怎么用?Python FigureCanvasQTAgg.setContentsMargins使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg的用法示例。


在下文中一共展示了FigureCanvasQTAgg.setContentsMargins方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: PlotHandler

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setContentsMargins [as 别名]
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)
开发者ID:Nialaren,项目名称:bia_project,代码行数:80,代码来源:matplotlibPlotHandler.py

示例2: PlotWidget

# 需要导入模块: from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg [as 别名]
# 或者: from matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg import setContentsMargins [as 别名]
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()
开发者ID:frankfx,项目名称:master_thesis,代码行数:82,代码来源:plotWidget.py


注:本文中的matplotlib.backends.backend_qt4agg.FigureCanvasQTAgg.setContentsMargins方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。