How to use the persim.plot_diagrams function in persim

To help you get started, we’ve selected a few persim examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github scikit-tda / persim / test / test_visuals.py View on Github external
def test_set_title(self):
        diagrams = [
            np.array([[0, 1], [1, 1], [2, 4], [3, 5]]),
            np.array([[0.5, 3], [2, 4], [4, 5], [10, 15]])
        ]

        f, ax = plt.subplots()
        plot_diagrams(diagrams, title='my title', show=False)
        assert ax.get_title() == 'my title'

        f, ax = plt.subplots()
        plot_diagrams(diagrams, show=False)
        assert ax.get_title() == ''
github scikit-tda / persim / test / test_visuals.py View on Github external
def test_legend_true(self):
        diagrams = [
            np.array([[0, 1], [1, 1], [2, 4], [3, 5]]),
            np.array([[0.5, 3], [2, 4], [4, 5], [10, 15]])
        ]

        f, ax = plt.subplots()
        plot_diagrams(diagrams, legend=True, show=False)
        legend = [child for child in ax.get_children()
                  if child.__class__.__name__ == "Legend"]

        assert len(legend) == 1
github scikit-tda / persim / test / test_visuals.py View on Github external
def test_single(self):
        """ Most just test this doesn't crash
        """
        diagram = np.array([[0, 1], [1, 1], [2, 4], [3, 5]])

        f, ax = plt.subplots()
        plot_diagrams(diagram, show=False)

        x_plot, y_plot = ax.lines[0].get_xydata().T

        assert x_plot[0] <= np.min(diagram)
        assert x_plot[1] >= np.max(diagram)

        # get PathCollection
        pathcols = [child for child in ax.get_children()
                    if child.__class__.__name__ == "PathCollection"]
        assert len(pathcols) == 1
github scikit-tda / persim / test / test_visuals.py View on Github external
def test_plot_only(self):
        diagrams = [
            np.array([[0, 1], [1, 1], [2, 4], [3, 5]]),
            np.array([[0.5, 3], [2, 4], [4, 5], [10, 15]])
        ]
        f, ax = plt.subplots()
        plot_diagrams(diagrams, legend=False, show=False, plot_only=[1])
github scikit-tda / persim / test / test_visuals.py View on Github external
def test_default_square(self):
        diagrams = [
            np.array([[0, 1], [1, 1], [2, 4], [3, 5]]),
            np.array([[0.5, 3], [2, 4], [4, 5], [10, 15]])
        ]

        f, ax = plt.subplots()
        plot_diagrams(diagrams, show=False)
        diagonal = ax.lines[0].get_xydata()

        assert diagonal[0, 0] == diagonal[0, 1]
        assert diagonal[1, 0] == diagonal[1, 1]
github scikit-tda / persim / test / test_visuals.py View on Github external
def test_multiple(self):
        diagrams = [
            np.array([[0, 1], [1, 1], [2, 4], [3, 5]]),
            np.array([[0.5, 3], [2, 4], [4, 5], [10, 15]])
        ]

        f, ax = plt.subplots()
        plot_diagrams(diagrams, show=False)

        pathcols = [child for child in ax.get_children()
                    if child.__class__.__name__ == "PathCollection"]

        assert len(pathcols) == 2
        np.testing.assert_array_equal(pathcols[0].get_offsets(), diagrams[0])
        np.testing.assert_array_equal(pathcols[1].get_offsets(), diagrams[1])
github scikit-tda / persim / test / test_visuals.py View on Github external
def test_lifetime_removes_birth(self):
        diagrams = [
            np.array([[0, 1], [1, 1], [2, 4], [3, 5]]),
            np.array([[0.5, 3], [2, 4], [4, 5], [10, 15]])
        ]

        f, ax = plt.subplots()
        plot_diagrams(diagrams, lifetime=True, show=False)

        pathcols = [child for child in ax.get_children()
                    if child.__class__.__name__ == "PathCollection"]

        modded1 = diagrams[0]
        modded1[:, 1] = diagrams[0][:, 1] - diagrams[0][:, 0]
        modded2 = diagrams[1]
        modded2[:, 1] = diagrams[1][:, 1] - diagrams[1][:, 0]
        assert len(pathcols) == 2
        np.testing.assert_array_equal(pathcols[0].get_offsets(), modded1)
        np.testing.assert_array_equal(pathcols[1].get_offsets(), modded2)
github scikit-tda / persim / test / test_visuals.py View on Github external
def test_legend_false(self):
        diagrams = [
            np.array([[0, 1], [1, 1], [2, 4], [3, 5]]),
            np.array([[0.5, 3], [2, 4], [4, 5], [10, 15]])
        ]

        f, ax = plt.subplots()
        plot_diagrams(diagrams, legend=False, show=False)
        legend = [child for child in ax.get_children()
                  if child.__class__.__name__ == "Legend"]

        assert len(legend) == 0
github scikit-tda / persim / test / test_visuals.py View on Github external
def test_infty(self):
        diagrams = [
            np.array([[0, np.inf], [1, 1], [2, 4], [3, 5]]),
            np.array([[0.5, 3], [2, 4], [4, 5], [10, 15]])
        ]

        f, ax = plt.subplots()
        plot_diagrams(diagrams, legend=True, show=False)
github scikit-tda / ripser.py / ripser / ripser.py View on Github external
Essentially, visualize (x, y-x).

        legend: bool, default is True
            If true, show the legend.

        show: bool, default is True
            Call plt.show() after plotting. 
            If you are using self.plot() as part of a subplot, 
            set show=False and call plt.show() only once at the end.
        """

        if diagrams is None:
            # Allow using transformed diagrams as default
            diagrams = self.dgms_

        persim.plot_diagrams(
            diagrams,
            *args,
            **kwargs
        )