Python matplotlib.pyplot.fignum_exists() Examples

The following are 10 code examples of matplotlib.pyplot.fignum_exists(). 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.pyplot , or try the search function .
Example #1
Source File: test_figure.py    From tensorboardX with MIT License 6 votes vote down vote up
def test_figure(self):
        writer = SummaryWriter()

        figure, axes = plt.figure(), plt.gca()
        circle1 = plt.Circle((0.2, 0.5), 0.2, color='r')
        circle2 = plt.Circle((0.8, 0.5), 0.2, color='g')
        axes.add_patch(circle1)
        axes.add_patch(circle2)
        plt.axis('scaled')
        plt.tight_layout()

        writer.add_figure("add_figure/figure", figure, 0, close=False)
        assert plt.fignum_exists(figure.number) is True

        writer.add_figure("add_figure/figure", figure, 1)
        assert plt.fignum_exists(figure.number) is False

        writer.close() 
Example #2
Source File: test_figure.py    From tensorboardX with MIT License 6 votes vote down vote up
def test_figure_list(self):
        writer = SummaryWriter()

        figures = []
        for i in range(5):
            figure = plt.figure()
            plt.plot([i * 1, i * 2, i * 3], label="Plot " + str(i))
            plt.xlabel("X")
            plt.xlabel("Y")
            plt.legend()
            plt.tight_layout()
            figures.append(figure)

        writer.add_figure("add_figure/figure_list", figures, 0, close=False)
        assert all([plt.fignum_exists(figure.number) is True for figure in figures])

        writer.add_figure("add_figure/figure_list", figures, 1)
        assert all([plt.fignum_exists(figure.number) is False for figure in figures])

        writer.close() 
Example #3
Source File: easyplot.py    From easyplot with MIT License 5 votes vote down vote up
def redraw(self):
        """
        Redraw plot. Use after custom user modifications of axes & fig objects
        """
        if plt.isinteractive():
            fig = self.kwargs['fig']
            #Redraw figure if it was previously closed prior to updating it
            if not plt.fignum_exists(fig.number):
                fig.show()
            fig.canvas.draw()
        else:
            print('redraw() is unsupported in non-interactive plotting mode!') 
Example #4
Source File: test_figure.py    From python3_ios with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def test_fignum_exists():
    # pyplot figure creation, selection and closing with fignum_exists
    plt.figure('one')
    plt.figure(2)
    plt.figure('three')
    plt.figure()
    assert plt.fignum_exists('one')
    assert plt.fignum_exists(2)
    assert plt.fignum_exists('three')
    assert plt.fignum_exists(4)
    plt.close('one')
    plt.close(4)
    assert not plt.fignum_exists('one')
    assert not plt.fignum_exists(4) 
Example #5
Source File: plotting.py    From robel with Apache License 2.0 5 votes vote down vote up
def is_open(self) -> bool:
        """Returns True if the figure window is open."""
        return plt.fignum_exists(self.fig.number) 
Example #6
Source File: display_image.py    From style_transfer with MIT License 5 votes vote down vote up
def display(self, image):
        if self.imsh is None or not plt.fignum_exists(self.imsh.figure.number):
            self.imsh = plt.imshow(image, interpolation='nearest')
            self.imsh.axes.axis('off')
            self.imsh.axes.set_position((0, 0, 1, 1))
            self.imsh.figure.canvas.draw()
        else:
            self.imsh.set_data(image)
        plt.pause(1e-4) 
Example #7
Source File: test_figure.py    From coffeegrindsize with MIT License 5 votes vote down vote up
def test_fignum_exists():
    # pyplot figure creation, selection and closing with fignum_exists
    plt.figure('one')
    plt.figure(2)
    plt.figure('three')
    plt.figure()
    assert plt.fignum_exists('one')
    assert plt.fignum_exists(2)
    assert plt.fignum_exists('three')
    assert plt.fignum_exists(4)
    plt.close('one')
    plt.close(4)
    assert not plt.fignum_exists('one')
    assert not plt.fignum_exists(4) 
Example #8
Source File: plot.py    From pyexperiment with MIT License 5 votes vote down vote up
def plot_process(queue,
                     name,
                     labels=None,
                     x_scale='linear',
                     y_scale='linear'):
        """Grabs data from the queue and plots it in a named figure
        """
        # Set up the figure and display it
        fig = setup_figure(name)
        plt.show(block=False)
        if labels is not None:
            plt.xlabel(labels[0])
            plt.ylabel(labels[1])
        plt.xscale(x_scale)
        plt.yscale(y_scale)

        while True:
            # Get all the data currently on the queue
            data = []
            while not queue.empty():
                data.append(queue.get())

            # If there is no data, no need to plot, instead wait for a
            # while
            if len(data) == 0 and plt.fignum_exists(fig.number):
                plt.pause(0.015)
                continue

            # Check if poison pill (None) arrived or the figure was closed
            if None in data or not plt.fignum_exists(fig.number):
                # If yes, close the figure and leave the process
                plt.close(fig)
                break
            else:
                # Plot the data, then wait 15ms for the plot to update
                for datum in data:
                    plt.plot(*datum[0], **datum[1])
                plt.pause(0.015) 
Example #9
Source File: test_figure.py    From twitter-stock-recommendation with MIT License 5 votes vote down vote up
def test_fignum_exists():
    # pyplot figure creation, selection and closing with fignum_exists
    plt.figure('one')
    plt.figure(2)
    plt.figure('three')
    plt.figure()
    assert plt.fignum_exists('one')
    assert plt.fignum_exists(2)
    assert plt.fignum_exists('three')
    assert plt.fignum_exists(4)
    plt.close('one')
    plt.close(4)
    assert not plt.fignum_exists('one')
    assert not plt.fignum_exists(4) 
Example #10
Source File: test_run_tracking.py    From polyaxon with Apache License 2.0 4 votes vote down vote up
def test_log_mpl_plotly(self):
        assert (
            os.path.exists(get_event_path(self.run_path, kind=V1ArtifactKind.CHART))
            is False
        )
        assert (
            os.path.exists(get_asset_path(self.run_path, kind=V1ArtifactKind.CHART))
            is False
        )

        figure, axes = plt.figure(), plt.gca()
        circle1 = plt.Circle((0.2, 0.5), 0.2, color="r")
        circle2 = plt.Circle((0.8, 0.5), 0.2, color="g")
        axes.add_patch(circle1)
        axes.add_patch(circle2)
        plt.axis("scaled")
        plt.tight_layout()

        with patch("polyaxon.tracking.run.Run._log_has_events") as log_dashboard:
            self.run.log_mpl_plotly_chart(name="figure", figure=figure, step=1)
        assert log_dashboard.call_count == 1

        self.event_logger.flush()
        assert (
            os.path.exists(get_asset_path(self.run_path, kind=V1ArtifactKind.CHART))
            is False
        )
        assert (
            os.path.exists(get_event_path(self.run_path, kind=V1ArtifactKind.CHART))
            is True
        )
        events_file = get_event_path(
            self.run_path, kind=V1ArtifactKind.CHART, name="figure"
        )
        assert os.path.exists(events_file) is True
        results = V1Events.read(kind="image", name="figure", data=events_file)
        assert len(results.df.values) == 1

        with patch("polyaxon.tracking.run.Run._log_has_events") as log_dashboard:
            self.run.log_mpl_plotly_chart(name="figure", figure=figure, step=2)
        assert log_dashboard.call_count == 1
        assert plt.fignum_exists(figure.number) is False

        self.event_logger.flush()
        assert (
            os.path.exists(get_asset_path(self.run_path, kind=V1ArtifactKind.CHART))
            is False
        )
        assert (
            os.path.exists(get_event_path(self.run_path, kind=V1ArtifactKind.CHART))
            is True
        )
        events_file = get_event_path(
            self.run_path, kind=V1ArtifactKind.CHART, name="figure"
        )
        assert os.path.exists(events_file) is True
        results = V1Events.read(kind="image", name="figure", data=events_file)
        assert len(results.df.values) == 2