Python matplotlib.figure.Figure() Examples

The following are 30 code examples of matplotlib.figure.Figure(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module matplotlib.figure , or try the search function .
Example #1
Source File: plotter.py    From visma with GNU General Public License v3.0 7 votes vote down vote up
def plotFigure2D(workspace):
    """GUI layout for plot figure

    Arguments:
        workspace {QtWidgets.QWidget} -- main layout

    Returns:
        layout {QtWidgets.QVBoxLayout} -- contains matplot figure
    """
    workspace.figure2D = Figure()
    workspace.canvas2D = FigureCanvas(workspace.figure2D)
    # workspace.figure2D.patch.set_facecolor('white')

    class NavigationCustomToolbar(NavigationToolbar):
        toolitems = [t for t in NavigationToolbar.toolitems if t[0] in ()]

    workspace.toolbar2D = NavigationCustomToolbar(workspace.canvas2D, workspace)
    layout = QVBoxLayout()
    layout.addWidget(workspace.canvas2D)
    layout.addWidget(workspace.toolbar2D)
    return layout 
Example #2
Source File: dialog_timeline.py    From RF-Monitor with GNU General Public License v2.0 6 votes vote down vote up
def __setup_plot(self):
        figure = Figure(facecolor='lightgrey')

        self._axes = figure.add_subplot(111)
        self._axes.set_title('Timeline')
        self._axes.set_xlabel('Time')
        self._axes.set_ylabel('Frequency (MHz)')
        self._axes.grid(True)

        locator = AutoDateLocator()
        formatter = AutoDateFormatter(locator)
        self._axes.xaxis.set_major_formatter(formatter)
        self._axes.xaxis.set_major_locator(locator)
        formatter = ScalarFormatter(useOffset=False)
        self._axes.yaxis.set_major_formatter(formatter)
        self._axes.yaxis.set_minor_locator(AutoMinorLocator(10))

        self._canvas = FigureCanvas(self._panelPlot, -1, figure)
        self._canvas.mpl_connect('motion_notify_event', self.__on_motion)

        Legend.__init__(self, self._axes, self._canvas) 
Example #3
Source File: board.py    From seagull with MIT License 6 votes vote down vote up
def view(self, figsize=(5, 5)) -> Tuple[Figure, AxesImage]:
        """View the current state of the board

        Parameters
        ----------
        figsize : tuple
            Size of the output figure

        Returns
        -------
        (:obj:`matplotlib.figure.Figure`, :obj:`matplotlib.image.AxesImage`)
            Graphical view of the board
        """
        fig = plt.figure(figsize=figsize)
        ax = fig.add_axes([0, 0, 1, 1], xticks=[], yticks=[], frameon=False)
        im = ax.imshow(self.state, cmap=plt.cm.binary, interpolation="nearest")
        im.set_clim(-0.05, 1)
        return fig, im 
Example #4
Source File: view.py    From ms_deisotope with Apache License 2.0 6 votes vote down vote up
def configure_canvas(self):
        self.figure = Figure(dpi=100)
        self.canvas = FigureCanvasTkAgg(self.figure, master=self)
        self.axis = self.figure.add_subplot(111)
        self.canvas.draw()
        canvas_widget = self.canvas.get_tk_widget()
        canvas_widget.grid(row=0, column=0, sticky=tk.N + tk.W + tk.E + tk.S)
        self.canvas_cursor = Cursor(self.axis, tk.StringVar(master=self.root))
        self.canvas.mpl_connect('motion_notify_event', self.canvas_cursor.mouse_move)
        self.span = SpanSelector(
            self.axis, self.zoom, 'horizontal', useblit=True,
            rectprops=dict(alpha=0.5, facecolor='red'))
        self.mz_span = None
        self.scan = None
        self.annotations = []
        self.canvas.draw() 
Example #5
Source File: sim_gui.py    From ocelot with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, parent=None, width=5, height=4, dpi=100):
        fig = Figure(figsize=(width, height), dpi=dpi)
        self.axes = fig.add_subplot(111)
        # We want the axes cleared every time plot() is called
        self.axes.hold(False)

        self.compute_initial_figure()

        #
        FigureCanvas.__init__(self, fig)
        self.setParent(parent)

        FigureCanvas.setSizePolicy(self,
                                   QtGui.QSizePolicy.Expanding,
                                   QtGui.QSizePolicy.Expanding)
        FigureCanvas.updateGeometry(self) 
Example #6
Source File: playbackFrame.py    From PyEveLiveDPS with GNU General Public License v3.0 6 votes vote down vote up
def makeGraph(self):
        self.graphFigure = Figure(figsize=(1,0.1), dpi=50, facecolor="black")
        
        self.subplot = self.graphFigure.add_subplot(1,1,1, facecolor=(0.3, 0.3, 0.3))
        self.subplot.tick_params(axis="y", colors="grey", labelbottom="off", bottom="off")
        self.subplot.tick_params(axis="x", colors="grey", labelbottom="off", bottom="off")
        
        self.graphFigure.axes[0].get_xaxis().set_ticklabels([])
        self.graphFigure.subplots_adjust(left=0, bottom=0, right=1, top=1, wspace=0, hspace=0)

        self.graphCanvas = FigureCanvasTkAgg(self.graphFigure, self)
        self.graphCanvas.get_tk_widget().configure(bg="black")
        self.graphCanvas.get_tk_widget().grid(row="2", column="2", columnspan="3", sticky="news")
        
        yValues = self.mainWindow.characterDetector.playbackLogReader.logEntryFrequency
        self.highestValue = 0
        for value in yValues:
            if value > self.highestValue: self.highestValue = value
        self.subplot.plot(yValues, "dodgerblue")
        self.timeLine, = self.subplot.plot([0, 0], [0, self.highestValue], "white")
        #self.graphFigure.axes[0].set_xlim(0, len(yValues))
        self.subplot.margins(0.005,0.01)
        
        self.graphCanvas.show()
        self.mainWindow.makeDraggable(self.graphCanvas.get_tk_widget()) 
Example #7
Source File: graph.py    From PyEveLiveDPS with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, parent, **kwargs):
        tk.Frame.__init__(self, parent, **kwargs)
        
        self.parent = parent
        self.degree = 5
        
        self.graphFigure = Figure(figsize=(4,2), dpi=100, facecolor="black")
        
        self.subplot = self.graphFigure.add_subplot(1,1,1, facecolor=(0.3, 0.3, 0.3))
        self.subplot.tick_params(axis="y", colors="grey", direction="in")
        self.subplot.tick_params(axis="x", colors="grey", labelbottom="off", bottom="off")
        
        self.graphFigure.axes[0].get_xaxis().set_ticklabels([])
        self.graphFigure.subplots_adjust(left=(30/100), bottom=(15/100), 
                                         right=1, top=(1-15/100), wspace=0, hspace=0)

        self.canvas = FigureCanvasTkAgg(self.graphFigure, self)
        self.canvas.get_tk_widget().configure(bg="black")
        self.canvas.get_tk_widget().pack(side=tk.BOTTOM, fill=tk.BOTH, expand=True)
        
        self.canvas.show() 
Example #8
Source File: steps.py    From visma with GNU General Public License v3.0 6 votes vote down vote up
def stepsFigure(workspace):
    """GUI layout for step-by-step solution

    Arguments:
        workspace {QtWidgets.QWidget} -- main layout

    Returns:
        stepslayout {QtWidgets.QVBoxLayout} -- step-by-step solution layout
    """
    workspace.stepsfigure = Figure()
    workspace.stepscanvas = FigureCanvas(workspace.stepsfigure)
    workspace.stepsfigure.clear()
    workspace.scroll = QScrollArea()
    workspace.scroll.setWidget(workspace.stepscanvas)
    stepslayout = QVBoxLayout()
    stepslayout.addWidget(workspace.scroll)
    return stepslayout 
Example #9
Source File: plotter.py    From visma with GNU General Public License v3.0 6 votes vote down vote up
def plotFigure3D(workspace):
    """GUI layout for plot figure

    Arguments:
        workspace {QtWidgets.QWidget} -- main layout

    Returns:
        layout {QtWidgets.QVBoxLayout} -- contains matplot figure
    """
    workspace.figure3D = Figure()
    workspace.canvas3D = FigureCanvas(workspace.figure3D)
    # workspace.figure3D.patch.set_facecolor('white')

    class NavigationCustomToolbar(NavigationToolbar):
        toolitems = [t for t in NavigationToolbar.toolitems if t[0] in ()]

    workspace.toolbar3D = NavigationCustomToolbar(workspace.canvas3D, workspace)
    layout = QVBoxLayout()
    layout.addWidget(workspace.canvas3D)
    layout.addWidget(workspace.toolbar3D)
    return layout 
Example #10
Source File: qsolver.py    From visma with GNU General Public License v3.0 6 votes vote down vote up
def qSolveFigure(workspace):
    """GUI layout for quick simplifier

    Arguments:
        workspace {QtWidgets.QWidget} -- main layout

    Returns:
        qSolLayout {QtWidgets.QVBoxLayout} -- quick simplifier layout
    """

    bg = workspace.palette().window().color()
    bgcolor = (bg.redF(), bg.greenF(), bg.blueF())
    workspace.qSolveFigure = Figure(edgecolor=bgcolor, facecolor=bgcolor)
    workspace.solcanvas = FigureCanvas(workspace.qSolveFigure)
    workspace.qSolveFigure.clear()
    qSolLayout = QtWidgets.QVBoxLayout()
    qSolLayout.addWidget(workspace.solcanvas)

    return qSolLayout 
Example #11
Source File: backend_wx.py    From Computable with MIT License 6 votes vote down vote up
def configure_subplots(self, evt):
        frame = wx.Frame(None, -1, "Configure subplots")

        toolfig = Figure((6,3))
        canvas = self.get_canvas(frame, toolfig)

        # Create a figure manager to manage things
        figmgr = FigureManager(canvas, 1, frame)

        # Now put all into a sizer
        sizer = wx.BoxSizer(wx.VERTICAL)
        # This way of adding to sizer allows resizing
        sizer.Add(canvas, 1, wx.LEFT|wx.TOP|wx.GROW)
        frame.SetSizer(sizer)
        frame.Fit()
        tool = SubplotTool(self.canvas.figure, toolfig)
        frame.Show() 
Example #12
Source File: backend_wx.py    From Computable with MIT License 6 votes vote down vote up
def __init__(self, targetfig):
        wx.Frame.__init__(self, None, -1, "Configure subplots")

        toolfig = Figure((6,3))
        canvas = FigureCanvasWx(self, -1, toolfig)

        # Create a figure manager to manage things
        figmgr = FigureManager(canvas, 1, self)

        # Now put all into a sizer
        sizer = wx.BoxSizer(wx.VERTICAL)
        # This way of adding to sizer allows resizing
        sizer.Add(canvas, 1, wx.LEFT|wx.TOP|wx.GROW)
        self.SetSizer(sizer)
        self.Fit()
        tool = SubplotTool(targetfig, toolfig) 
Example #13
Source File: gui.py    From skan with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def make_figure_window(self):
        self.figure_window = tk.Toplevel(self)
        self.figure_window.wm_title('Preview')
        screen_dpi = self.figure_window.winfo_fpixels('1i')
        screen_width = self.figure_window.winfo_screenwidth()  # in pixels
        figure_width = screen_width / 2 / screen_dpi
        figure_height = 0.75 * figure_width
        self.figure = Figure(figsize=(figure_width, figure_height),
                             dpi=screen_dpi)
        ax0 = self.figure.add_subplot(221)
        axes = [self.figure.add_subplot(220 + i, sharex=ax0, sharey=ax0)
                for i in range(2, 5)]
        self.axes = np.array([ax0] + axes)
        canvas = FigureCanvasTkAgg(self.figure, master=self.figure_window)
        canvas.show()
        canvas.get_tk_widget().pack(side=tk.TOP, fill=tk.BOTH, expand=1)
        toolbar = NavigationToolbar2Tk(canvas, self.figure_window)
        toolbar.update()
        canvas._tkcanvas.pack(side=tk.TOP, fill=tk.BOTH, expand=1) 
Example #14
Source File: backend_pdf.py    From Computable with MIT License 6 votes vote down vote up
def savefig(self, figure=None, **kwargs):
        """
        Save the Figure instance *figure* to this file as a new page.
        If *figure* is a number, the figure instance is looked up by
        number, and if *figure* is None, the active figure is saved.
        Any other keyword arguments are passed to Figure.savefig.
        """
        if isinstance(figure, Figure):
            figure.savefig(self, format='pdf', **kwargs)
        else:
            if figure is None:
                figureManager = Gcf.get_active()
            else:
                figureManager = Gcf.get_fig_manager(figure)
            if figureManager is None:
                raise ValueError("No such figure: " + repr(figure))
            else:
                figureManager.canvas.figure.savefig(self, format='pdf', **kwargs) 
Example #15
Source File: _pick_info.py    From mplcursors with MIT License 6 votes vote down vote up
def _format_scalarmappable_value(artist, idx):  # matplotlib/matplotlib#12473.
    data = artist.get_array()[idx]
    if np.ndim(data) == 0:
        if not artist.colorbar:
            fig = Figure()
            ax = fig.subplots()
            artist.colorbar = fig.colorbar(artist, cax=ax)
            # This hack updates the ticks without actually paying the cost of
            # drawing (RendererBase.draw_path raises NotImplementedError).
            try:
                ax.yaxis.draw(RendererBase())
            except NotImplementedError:
                pass
        fmt = artist.colorbar.formatter.format_data_short
        return "[" + _strip_math(fmt(data).strip()) + "]"
    else:
        return artist.format_cursor_data(data)  # Includes brackets. 
Example #16
Source File: matplotlibwidget.py    From Python-GUI-examples with MIT License 6 votes vote down vote up
def __init__(self, parent=None, title='', xlabel='', ylabel='',
                 xlim=None, ylim=None, xscale='linear', yscale='linear',
                 width=4, height=3, dpi=100, hold=False):
        self.figure = Figure(figsize=(width, height), dpi=dpi)
        self.axes = self.figure.add_subplot(111)
        self.axes.set_title(title)
        self.axes.set_xlabel(xlabel)
        self.axes.set_ylabel(ylabel)
        if xscale is not None:
            self.axes.set_xscale(xscale)
        if yscale is not None:
            self.axes.set_yscale(yscale)
        if xlim is not None:
            self.axes.set_xlim(*xlim)
        if ylim is not None:
            self.axes.set_ylim(*ylim)
        self.axes.hold(hold)

        Canvas.__init__(self, self.figure)
        self.setParent(parent)

        Canvas.setSizePolicy(self, QSizePolicy.Expanding, QSizePolicy.Expanding)
        Canvas.updateGeometry(self) 
Example #17
Source File: dialog_spectrum.py    From RF-Monitor with GNU General Public License v2.0 6 votes vote down vote up
def __setup_plot(self):
        figure = Figure(facecolor='lightgrey')

        self._axes = figure.add_subplot(111)
        self._axes.set_title('Spectrum')
        self._axes.set_xlabel('Frequency (MHz)')
        self._axes.set_ylabel('Level (dB)')
        self._axes.autoscale_view(True, True, True)
        self._axes.grid(True)

        self._spectrum, = self._axes.plot([], [], 'b-', label='Spectrum')

        self._canvas = FigureCanvas(self._panelPlot, -1, figure)
        self._canvas.mpl_connect('motion_notify_event', self.__on_motion)

        Legend.__init__(self, self._axes, self._canvas) 
Example #18
Source File: backend_wx.py    From Mastering-Elasticsearch-7.0 with MIT License 5 votes vote down vote up
def configure_subplots(self):
        frame = wx.Frame(None, -1, "Configure subplots")
        _set_frame_icon(frame)

        toolfig = Figure((6, 3))
        canvas = self.get_canvas(frame, toolfig)

        # Now put all into a sizer
        sizer = wx.BoxSizer(wx.VERTICAL)
        # This way of adding to sizer allows resizing
        sizer.Add(canvas, 1, wx.LEFT | wx.TOP | wx.GROW)
        frame.SetSizer(sizer)
        frame.Fit()
        SubplotTool(self.canvas.figure, toolfig)
        frame.Show() 
Example #19
Source File: backend_gtk3.py    From Computable with MIT License 5 votes vote down vote up
def configure_subplots(self, button):
        toolfig = Figure(figsize=(6,3))
        canvas = self._get_canvas(toolfig)
        toolfig.subplots_adjust(top=0.9)
        tool =  SubplotTool(self.canvas.figure, toolfig)

        w = int (toolfig.bbox.width)
        h = int (toolfig.bbox.height)


        window = Gtk.Window()
        try:
            window.set_icon_from_file(window_icon)
        except (SystemExit, KeyboardInterrupt):
            # re-raise exit type Exceptions
            raise
        except:
            # we presumably already logged a message on the
            # failure of the main plot, don't keep reporting
            pass
        window.set_title("Subplot Configuration Tool")
        window.set_default_size(w, h)
        vbox = Gtk.Box()
        vbox.set_property("orientation", Gtk.Orientation.VERTICAL)
        window.add(vbox)
        vbox.show()

        canvas.show()
        vbox.pack_start(canvas, True, True, 0)
        window.show() 
Example #20
Source File: backend_macosx.py    From Computable with MIT License 5 votes vote down vote up
def prepare_configure_subplots(self):
        toolfig = Figure(figsize=(6,3))
        canvas = FigureCanvasMac(toolfig)
        toolfig.subplots_adjust(top=0.9)
        tool = SubplotTool(self.canvas.figure, toolfig)
        return canvas 
Example #21
Source File: backend_macosx.py    From Computable with MIT License 5 votes vote down vote up
def new_figure_manager(num, *args, **kwargs):
    """
    Create a new figure manager instance
    """
    FigureClass = kwargs.pop('FigureClass', Figure)
    figure = FigureClass(*args, **kwargs)
    return new_figure_manager_given_figure(num, figure) 
Example #22
Source File: backend_cocoaagg.py    From Computable with MIT License 5 votes vote down vote up
def new_figure_manager(num, *args, **kwargs):
    FigureClass = kwargs.pop('FigureClass', Figure)
    thisFig = FigureClass( *args, **kwargs )
    return new_figure_manager_given_figure(num, thisFig) 
Example #23
Source File: backend_qt4.py    From Computable with MIT License 5 votes vote down vote up
def new_figure_manager( num, *args, **kwargs ):
    """
    Create a new figure manager instance
    """
    thisFig = Figure(*args, **kwargs)
    return new_figure_manager_given_figure(num, thisFig) 
Example #24
Source File: backend_gtk3cairo.py    From Computable with MIT License 5 votes vote down vote up
def new_figure_manager(num, *args, **kwargs):
    """
    Create a new figure manager instance
    """
    FigureClass = kwargs.pop('FigureClass', Figure)
    thisFig = FigureClass(*args, **kwargs)
    return new_figure_manager_given_figure(num, thisFig) 
Example #25
Source File: backend_template.py    From Computable with MIT License 5 votes vote down vote up
def new_figure_manager(num, *args, **kwargs):
    """
    Create a new figure manager instance
    """
    # if a main-level app must be created, this (and
    # new_figure_manager_given_figure) is the usual place to
    # do it -- see backend_wx, backend_wxagg and backend_tkagg for
    # examples.  Not all GUIs require explicit instantiation of a
    # main-level app (egg backend_gtk, backend_gtkagg) for pylab
    FigureClass = kwargs.pop('FigureClass', Figure)
    thisFig = FigureClass(*args, **kwargs)
    return new_figure_manager_given_figure(num, thisFig) 
Example #26
Source File: backend_gdk.py    From Computable with MIT License 5 votes vote down vote up
def new_figure_manager(num, *args, **kwargs):
    """
    Create a new figure manager instance
    """
    FigureClass = kwargs.pop('FigureClass', Figure)
    thisFig = FigureClass(*args, **kwargs)
    return new_figure_manager_given_figure(num, thisFig) 
Example #27
Source File: backend_macosx.py    From Mastering-Elasticsearch-7.0 with MIT License 5 votes vote down vote up
def prepare_configure_subplots(self):
        toolfig = Figure(figsize=(6, 3))
        canvas = FigureCanvasMac(toolfig)
        toolfig.subplots_adjust(top=0.9)
        tool = SubplotTool(self.canvas.figure, toolfig)
        return canvas 
Example #28
Source File: backend_gtk3agg.py    From Computable with MIT License 5 votes vote down vote up
def new_figure_manager(num, *args, **kwargs):
    """
    Create a new figure manager instance
    """
    FigureClass = kwargs.pop('FigureClass', Figure)
    thisFig = FigureClass(*args, **kwargs)
    return new_figure_manager_given_figure(num, thisFig) 
Example #29
Source File: backend_gtkagg.py    From Computable with MIT License 5 votes vote down vote up
def new_figure_manager(num, *args, **kwargs):
    """
    Create a new figure manager instance
    """
    if DEBUG: print('backend_gtkagg.new_figure_manager')
    FigureClass = kwargs.pop('FigureClass', Figure)
    thisFig = FigureClass(*args, **kwargs)
    return new_figure_manager_given_figure(num, thisFig) 
Example #30
Source File: backend_svg.py    From Computable with MIT License 5 votes vote down vote up
def new_figure_manager(num, *args, **kwargs):
    FigureClass = kwargs.pop('FigureClass', Figure)
    thisFig = FigureClass(*args, **kwargs)
    return new_figure_manager_given_figure(num, thisFig)