Esempio n. 1
0
def complex_figure(filename, dpi=settings.DPI,
        width=settings.SINGLE_COLUMN_DEFAULT_SIZE_CM,
        height=settings.SINGLE_COLUMN_DEFAULT_SIZE_CM,
        draw_frame=False, right_label=False,
        **unused_kwargs):
    scaled_width = width / settings.CM_SCALE
    scaled_height = height / settings.CM_SCALE

    scaled_top_margin = 1 - settings.TOP_MARGIN / height
    scaled_bottom_margin = settings.BOTTOM_MARGIN / height

    scaled_left_margin = settings.LEFT_MARGIN / width
    scaled_right_margin = 1 - settings.RIGHT_MARGIN / width

    if right_label:
        figure = _Figure(dpi=dpi, frameon=draw_frame,
                linewidth=settings.DEFAULT_FRAME_LINE_WIDTH,
                figsize=(scaled_width, scaled_height),
                subplotpars=matplotlib.figure.SubplotParams(
                    bottom=scaled_bottom_margin,
                    left=scaled_left_margin,
                    right=scaled_right_margin))
    else:
        figure = _Figure(dpi=dpi, frameon=draw_frame,
                linewidth=settings.DEFAULT_FRAME_LINE_WIDTH,
                figsize=(scaled_width, scaled_height),
                subplotpars=matplotlib.figure.SubplotParams(
                    bottom=scaled_bottom_margin,
                    left=scaled_left_margin))

    yield figure

    canvas = _FigureCanvas(figure)

    figure.savefig(filename)
Esempio n. 2
0
def figure(interactive=False):
    if interactive:
        import pylab
        return pylab.figure()
    f = _Figure()
    canvas = _FigureCanvas(f)
    return f
Esempio n. 3
0
    def __init__(self, subplot=111, parent=None, width=5, height=4, dpi=100, 
                 figfacecolor=3*[0.941], style=None, **kwargs):

        #        super(MplCanvas, self).__init__(parent)
        if style is None:
            pass
        else:
            _mpl.style.use(style)

        # Create figure and axes
        self.fig = _Figure(figsize=(width, height), dpi=dpi, 
                           facecolor=figfacecolor, **kwargs)
        # Initialize the canvas
        FigureCanvas.__init__(self, self.fig)
        self.setParent(parent)
        
        self.setupAx(subplot=subplot, **kwargs)
        
        # Not really used, but could be used to have some sort of initial plot
        self.compute_initial_figure()

        # Set canvas size policies and geometry
        FigureCanvas.setSizePolicy(self, _QtWidgets.QSizePolicy.Expanding,
                                   _QtWidgets.QSizePolicy.Expanding)
        FigureCanvas.updateGeometry(self)

        # Create the toolbar and connect to canvas (self)
        self.toolbar = _NavigationToolbar(self, None)
def figure(interactive=False):
    if interactive:
        import pylab
        return pylab.figure()
    f = _Figure()
    canvas = _FigureCanvas(f)
    return f
Esempio n. 5
0
    def __init__(self, subplot=111, parent=None, width=5, height=4, dpi=100, 
                 figfacecolor=3*[0.941], style=None, **kwargs):

        #        super(MplCanvas, self).__init__(parent)
        if style is None:
            pass
        else:
            _mpl.style.use(style)
        self._mpl_v1 = _mpl.__version__.split('.')[0] == 1

        # Create figure and axes
        self.fig = _Figure(figsize=(width, height), dpi=dpi, 
                           facecolor=figfacecolor, **kwargs)
        # Initialize the canvas
        FigureCanvas.__init__(self, self.fig)
        self.setParent(parent)
        
        self.setupAx(subplot=subplot, **kwargs)
        
        # Not really used, but could be used to have some sort of initial plot
        self.compute_initial_figure()

        # Set canvas size policies and geometry
        FigureCanvas.setSizePolicy(self, _QtWidgets.QSizePolicy.Fixed,
                                   _QtWidgets.QSizePolicy.Fixed)
        FigureCanvas.updateGeometry(self)

        # Create the toolbar and connect to canvas (self)
        self.toolbar = _NavigationToolbar(self, None)
Esempio n. 6
0
        def __init__(self, parent=None, width=640, height=400):
            fig = _Figure(figsize=(width / 100.0, height / 100.0),
                          dpi=100,
                          facecolor='0.93')

            _Canvas.__init__(self, fig)
            self.setParent(parent)

            _Canvas.setSizePolicy(self, _QtGui.QSizePolicy.Expanding,
                                  _QtGui.QSizePolicy.Expanding)
            _Canvas.updateGeometry(self)
Esempio n. 7
0
 def __init__(self):
     """Initialize figure canvas."""
     self.fig = _Figure()
     self.fig.patch.set_facecolor('1')
     self.ax = self.fig.add_subplot(111, adjustable='datalim')
     _FigCanvas.__init__(self, self.fig)
     _FigCanvas.setSizePolicy(self, _QSizePolicy.Expanding,
                              _QSizePolicy.Expanding)
     _FigCanvas.updateGeometry(self)
     self.ax.ticklabel_format(style='sci', scilimits=(0, 0), axis='y')
     self.fig.tight_layout()
     self.fig.canvas.draw()
Esempio n. 8
0
    def __init__(self, parent=None):
        """Add figure canvas to layout."""
        super().__init__(parent)

        self.figure = _Figure()
        self.canvas = _FigureCanvas(self.figure)
        self.ax = self.figure.add_subplot(111)

        _layout = QtWidgets.QVBoxLayout()
        _layout.addWidget(self.canvas)
        self.toolbar = _Toolbar(self.canvas, self)
        _layout.addWidget(self.toolbar)
        self.setLayout(_layout)
Esempio n. 9
0
        winTest.ui.mpl.canvas.draw()

    class _winMpl:
        def __init__(self):
            self.fig = None
            self.ax = None
            self.img = None
            self.canvas = None
            self.toolbar = None

    app = _QApplication(_sys.argv)

    winTest = testWindow()
    winTest.ui.mpl = _winMpl()
    winTest.ui.mpl.fig = _Figure()
    winTest.ui.mpl.ax = winTest.ui.mpl.fig.add_subplot(111)

    data = _np.random.rand(20, 20, 50)
    data_slice = data[:, :, 25]

    winTest.ui.mpl.img = winTest.ui.mpl.ax.imshow(data_slice,
                                                  interpolation='none',
                                                  cmap=_mpl.cm.gray,
                                                  origin='lower')
    winTest.ui.mpl.canvas = _FigureCanvas(winTest.ui.mpl.fig)

    winTest.ui.verticalLayout.insertWidget(0, winTest.ui.mpl.canvas)

    winTest.ui.pushbutton.pressed.connect(buttonPress)
Esempio n. 10
0
    def __init__(self,
                 data,
                 x=None,
                 plugin=None,
                 xlabel=None,
                 ylabel=None,
                 show_difference=False,
                 parent=None):
        super(DialogPlotEffect, self).__init__(parent)
        self.ui = Ui_DialogPlotEffect()
        self.ui.setupUi(self)

        self.data = data

        self.mpl_orig = _winMpl()
        self.mpl_orig.fig = _Figure(facecolor=[1, 1, 1])
        self.mpl_orig.ax = self.mpl_orig.fig.add_subplot(111)
        self.mpl_orig.canvas = _FigureCanvas(self.mpl_orig.fig)
        self.mpl_orig.toolbar = _NavigationToolbar(self.mpl_orig.canvas, None)

        self.mpl_affected = _winMpl()
        self.mpl_affected.fig = _Figure(facecolor=[1, 1, 1])
        self.mpl_affected.ax = self.mpl_affected.fig.add_subplot(111)
        self.mpl_affected.canvas = _FigureCanvas(self.mpl_affected.fig)
        self.mpl_affected.toolbar = _NavigationToolbar(
            self.mpl_affected.canvas, None)

        self.ui.verticalLayout.insertWidget(1, self.mpl_orig.canvas)
        self.ui.verticalLayout.insertWidget(1, self.mpl_orig.toolbar)

        self.ui.verticalLayout.insertWidget(3, self.mpl_affected.canvas)
        self.ui.verticalLayout.insertWidget(3, self.mpl_affected.toolbar)

        # Plugin that brings functionality to PlotEffect
        self.plugin = plugin

        # Signal emited when something changes in the plugin widget
        self.plugin.changed.connect(self.widget_changed)

        if xlabel is None:
            self.ui.xlabel = self.XLABEL
        else:
            self.ui.xlabel = xlabel

        if ylabel is None:
            self.ui.ylabel = self.YLABEL
        else:
            self.ui.ylabel = ylabel

        if x is None:
            self.x = _np.linspace(0, data.shape[0], self.data.shape[0])
        else:
            self.x = x

        self.show_diff = show_difference

        if not isinstance(data, list):
            try:
                self.mpl_orig.ax.plot(self.x, data)
            except:
                self.mpl_orig.ax.plot(self.x, data.T)

            self.mpl_orig.ax.xaxis.set_label_text(self.ui.xlabel)
            self.mpl_orig.ax.yaxis.set_label_text(self.ui.ylabel)
            #            self.mpl_orig.fig.tight_layout(rect=[-.05,0.05,1,.95])
            self.mpl_orig.ax.set_title('Original')
        else:
            if self.plugin is not None:

                try:
                    self.mpl_orig.ax.plot(self.x, self.plugin.fcn(self.data))
                except:
                    self.mpl_orig.ax.plot(self.x, self.plugin.fcn(self.data).T)

                self.mpl_orig.ax.xaxis.set_label_text(self.ui.xlabel)
                self.mpl_orig.ax.yaxis.set_label_text(self.ui.ylabel)
                #                self.mpl_orig.fig.tight_layout(rect=[0,0.05,1,.9])
                self.mpl_orig.ax.set_title('Original')

        if self.plugin is not None:
            self.ui.verticalLayout.insertWidget(8, plugin)

        self.widget_changed()
        self.mpl_orig.canvas.draw()
        self.mpl_affected.canvas.draw()

        self.ui.pushButtonOk.clicked.connect(self.accept)
        self.ui.pushButtonCancel.clicked.connect(self.reject)
Esempio n. 11
0
        winTest.ui.mpl.canvas.draw()

    class _winMpl:
        def __init__(self):
            self.fig = None
            self.ax = None
            self.img = None
            self.canvas = None
            self.toolbar = None

    app = _QApplication(_sys.argv)

    winTest = testWindow()
    winTest.ui.mpl = _winMpl()
    winTest.ui.mpl.fig = _Figure()
    winTest.ui.mpl.ax = winTest.ui.mpl.fig.add_subplot(111)

    data = _np.random.rand(20,20,50)
    data_slice = data[:,:,25]

    winTest.ui.mpl.img = winTest.ui.mpl.ax.imshow(data_slice, interpolation='none', cmap = _mpl.cm.gray , origin='lower')
    winTest.ui.mpl.canvas = _FigureCanvas(winTest.ui.mpl.fig)

    winTest.ui.verticalLayout.insertWidget(0,winTest.ui.mpl.canvas)

    winTest.ui.pushbutton.pressed.connect(buttonPress)

    winTest.show()

    selectiondata = ImageSelection()