From 0902c35ad4701d78a91b30e2d055a529f4de01d5 Mon Sep 17 00:00:00 2001 From: vrouvrea Date: Fri, 27 Apr 2018 16:03:43 +0000 Subject: Remove show_palette_values Add legend flag to display the legend Set rips threshold to 0.3 for users not to be surprised when playing with threshold git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/python_2.1.0_fix_vincent@3406 636b058d-ea47-450e-bf9e-a15bfbe3eedb Former-commit-id: 03999711eafb81748a82b5725482a9f0d4307861 --- src/cython/cython/persistence_graphical_tools.py | 43 ++++++++++------------ src/cython/doc/persistence_graphical_tools_ref.rst | 1 - .../doc/persistence_graphical_tools_user.rst | 22 +---------- src/cython/doc/pyplots/diagram_persistence.py | 2 +- src/cython/doc/pyplots/show_palette_values.py | 3 -- .../example/gudhi_graphical_tools_example.py | 5 --- 6 files changed, 23 insertions(+), 53 deletions(-) delete mode 100755 src/cython/doc/pyplots/show_palette_values.py (limited to 'src/cython') diff --git a/src/cython/cython/persistence_graphical_tools.py b/src/cython/cython/persistence_graphical_tools.py index 98e875b0..118fdd1a 100755 --- a/src/cython/cython/persistence_graphical_tools.py +++ b/src/cython/cython/persistence_graphical_tools.py @@ -1,4 +1,5 @@ import matplotlib.pyplot as plt +import matplotlib.patches as mpatches import numpy as np import os @@ -59,26 +60,8 @@ palette = ['#ff0000', '#00ff00', '#0000ff', '#00ffff', '#ff00ff', '#ffff00', '#000000', '#880000', '#008800', '#000088', '#888800', '#880088', '#008888'] -def show_palette_values(alpha=0.6): - """This function shows palette color values in function of the dimension. - - :param alpha: alpha value in [0.0, 1.0] for horizontal bars (default is 0.6). - :type alpha: float. - :returns: A matplotlib object containing dimension palette values (launch - `show()` method on it to display it). - """ - colors = [] - for color in palette: - colors.append(color) - - y_pos = np.arange(len(palette)) - - plt.barh(y_pos, y_pos + 1, align='center', alpha=alpha, color=colors) - plt.ylabel('Dimension') - plt.title('Dimension palette values') - return plt - -def plot_persistence_barcode(persistence=[], persistence_file='', alpha=0.6, max_barcodes=1000): +def plot_persistence_barcode(persistence=[], persistence_file='', alpha=0.6, + max_barcodes=1000, inf_delta=0.1, legend=False): """This function plots the persistence bar code from persistence values list or from a :doc:`persistence file `. @@ -93,6 +76,9 @@ def plot_persistence_barcode(persistence=[], persistence_file='', alpha=0.6, max Set it to 0 to see all, Default value is 1000. (persistence will be sorted by life time if max_barcodes is set) :type max_barcodes: int. + :param inf_delta: Infinity is placed at ((max_death - min_birth) x inf_delta). + A reasonable value is between 0.05 and 0.5 - default is 0.1. + :type inf_delta: float. :returns: A matplotlib object containing horizontal bar plot of persistence (launch `show()` method on it to display it). """ @@ -116,7 +102,7 @@ def plot_persistence_barcode(persistence=[], persistence_file='', alpha=0.6, max (min_birth, max_death) = __min_birth_max_death(persistence) ind = 0 - delta = ((max_death - min_birth) / 10.0) + delta = ((max_death - min_birth) * inf_delta) # Replace infinity values with max_death + delta for bar code to be more # readable infinity = max_death + delta @@ -137,12 +123,16 @@ def plot_persistence_barcode(persistence=[], persistence_file='', alpha=0.6, max linewidth=0) ind = ind + 1 + if legend: + dimensions = list(set(item[0] for item in persistence)) + plt.legend(handles=[mpatches.Patch(color=palette[dim], label=str(dim)) for dim in dimensions]) plt.title('Persistence barcode') # Ends plot on infinity value and starts a little bit before min_birth plt.axis([axis_start, infinity, 0, ind]) return plt -def plot_persistence_diagram(persistence=[], persistence_file='', alpha=0.6, band=0., max_plots=1000): +def plot_persistence_diagram(persistence=[], persistence_file='', alpha=0.6, + band=0., max_plots=1000, inf_delta=0.1, legend=False): """This function plots the persistence diagram from persistence values list or from a :doc:`persistence file `. @@ -159,6 +149,9 @@ def plot_persistence_diagram(persistence=[], persistence_file='', alpha=0.6, ban Set it to 0 to see all, Default value is 1000. (persistence will be sorted by life time if max_plots is set) :type max_plots: int. + :param inf_delta: Infinity is placed at ((max_death - min_birth) x inf_delta). + A reasonable value is between 0.05 and 0.5 - default is 0.1. + :type inf_delta: float. :returns: A matplotlib object containing diagram plot of persistence (launch `show()` method on it to display it). """ @@ -180,7 +173,7 @@ def plot_persistence_diagram(persistence=[], persistence_file='', alpha=0.6, ban (min_birth, max_death) = __min_birth_max_death(persistence, band) ind = 0 - delta = ((max_death - min_birth) / 10.0) + delta = ((max_death - min_birth) * inf_delta) # Replace infinity values with max_death + delta for diagram to be more # readable infinity = max_death + delta @@ -208,6 +201,10 @@ def plot_persistence_diagram(persistence=[], persistence_file='', alpha=0.6, ban color = palette[interval[0]]) ind = ind + 1 + if legend: + dimensions = list(set(item[0] for item in persistence)) + plt.legend(handles=[mpatches.Patch(color=palette[dim], label=str(dim)) for dim in dimensions]) + plt.title('Persistence diagram') plt.xlabel('Birth') plt.ylabel('Death') diff --git a/src/cython/doc/persistence_graphical_tools_ref.rst b/src/cython/doc/persistence_graphical_tools_ref.rst index 27c2f68a..a69c8ba2 100644 --- a/src/cython/doc/persistence_graphical_tools_ref.rst +++ b/src/cython/doc/persistence_graphical_tools_ref.rst @@ -3,6 +3,5 @@ Persistence graphical tools reference manual ============================================ .. autofunction:: gudhi.__min_birth_max_death -.. autofunction:: gudhi.show_palette_values .. autofunction:: gudhi.plot_persistence_barcode .. autofunction:: gudhi.plot_persistence_diagram diff --git a/src/cython/doc/persistence_graphical_tools_user.rst b/src/cython/doc/persistence_graphical_tools_user.rst index 290b13c3..46f871c7 100644 --- a/src/cython/doc/persistence_graphical_tools_user.rst +++ b/src/cython/doc/persistence_graphical_tools_user.rst @@ -5,24 +5,6 @@ Definition .. include:: persistence_graphical_tools_sum.rst -Show palette values -------------------- - -This function is useful to show the color palette values of dimension: - - -.. testcode:: - - import gudhi - plt = gudhi.show_palette_values(alpha=1.0) - plt.show() - -.. plot:: - - import gudhi - plt = gudhi.show_palette_values(alpha=1.0) - plt.show() - Show persistence as a barcode ----------------------------- @@ -59,7 +41,7 @@ This function can display the persistence result as a diagram: import gudhi point_cloud = gudhi.read_off(off_file=gudhi.__root_source_dir__ + '/data/points/tore3D_1307.off') - rips_complex = gudhi.RipsComplex(points=point_cloud, max_edge_length=0.2) + rips_complex = gudhi.RipsComplex(points=point_cloud, max_edge_length=0.3) simplex_tree = rips_complex.create_simplex_tree(max_dimension=3) diag = simplex_tree.persistence() plt = gudhi.plot_persistence_diagram(diag) @@ -70,7 +52,7 @@ This function can display the persistence result as a diagram: import gudhi point_cloud = gudhi.read_off(off_file=gudhi.__root_source_dir__ + '/data/points/tore3D_1307.off') - rips_complex = gudhi.RipsComplex(points=point_cloud, max_edge_length=0.2) + rips_complex = gudhi.RipsComplex(points=point_cloud, max_edge_length=0.3) simplex_tree = rips_complex.create_simplex_tree(max_dimension=3) diag = simplex_tree.persistence() plt = gudhi.plot_persistence_diagram(diag) diff --git a/src/cython/doc/pyplots/diagram_persistence.py b/src/cython/doc/pyplots/diagram_persistence.py index 5abf52b9..3bab0ca1 100755 --- a/src/cython/doc/pyplots/diagram_persistence.py +++ b/src/cython/doc/pyplots/diagram_persistence.py @@ -2,7 +2,7 @@ import gudhi point_cloud = gudhi.read_off(off_file=gudhi.__root_source_dir__ + \ '/data/points/tore3D_1307.off') -rips_complex = gudhi.RipsComplex(points=point_cloud, max_edge_length=0.2) +rips_complex = gudhi.RipsComplex(points=point_cloud, max_edge_length=0.3) simplex_tree = rips_complex.create_simplex_tree(max_dimension=3) diag = simplex_tree.persistence() plt = gudhi.plot_persistence_diagram(diag) diff --git a/src/cython/doc/pyplots/show_palette_values.py b/src/cython/doc/pyplots/show_palette_values.py deleted file mode 100755 index fdf9645f..00000000 --- a/src/cython/doc/pyplots/show_palette_values.py +++ /dev/null @@ -1,3 +0,0 @@ -import gudhi -plt = gudhi.show_palette_values(alpha=1.0) -plt.show() diff --git a/src/cython/example/gudhi_graphical_tools_example.py b/src/cython/example/gudhi_graphical_tools_example.py index 97983262..d21d44c2 100755 --- a/src/cython/example/gudhi_graphical_tools_example.py +++ b/src/cython/example/gudhi_graphical_tools_example.py @@ -28,11 +28,6 @@ __author__ = "Vincent Rouvreau" __copyright__ = "Copyright (C) 2016 INRIA" __license__ = "GPL v3" -print("#####################################################################") -print("Show palette colors values for dimension") - -gudhi.show_palette_values() - print("#####################################################################") print("Show barcode persistence example") -- cgit v1.2.3