diff options
Diffstat (limited to 'src/python')
-rw-r--r-- | src/python/doc/persistence_graphical_tools_user.rst | 14 | ||||
-rw-r--r-- | src/python/gudhi/persistence_graphical_tools.py | 46 |
2 files changed, 43 insertions, 17 deletions
diff --git a/src/python/doc/persistence_graphical_tools_user.rst b/src/python/doc/persistence_graphical_tools_user.rst index b5a38eb1..5cdc2dca 100644 --- a/src/python/doc/persistence_graphical_tools_user.rst +++ b/src/python/doc/persistence_graphical_tools_user.rst @@ -90,3 +90,17 @@ If you want more information on a specific dimension, for instance: gudhi.plot_persistence_density(persistence=pers_diag, dimension=1, legend=True, axes=axes[1]) plt.show() + +LaTeX support +------------- + +By default, persistence graphical tools are using LaTeX support for matplotlib if available (cf. +`matplotlib text rendering with LaTeX <https://matplotlib.org/3.3.0/tutorials/text/usetex.html>`_). +It also requires `type1cm` LaTeX package (not detected by matplotlib). + +If you are facing issues with LaTeX rendering, you can still deactivate LaTeX rendering by saying: + +.. code-block:: python + + import gudhi + gudhi.persistence_graphical_tools._gudhi_matplotlib_use_tex=False diff --git a/src/python/gudhi/persistence_graphical_tools.py b/src/python/gudhi/persistence_graphical_tools.py index c6766c70..cce091d5 100644 --- a/src/python/gudhi/persistence_graphical_tools.py +++ b/src/python/gudhi/persistence_graphical_tools.py @@ -20,6 +20,20 @@ __author__ = "Vincent Rouvreau, Bertrand Michel, Theo Lacombe" __copyright__ = "Copyright (C) 2016 Inria" __license__ = "MIT" +@lru_cache(maxsize=1) +def _matplotlib_can_use_tex(): + """This function returns True if matplotlib can deal with LaTeX, False otherwise. + The returned value is cached. + """ + try: + from matplotlib import checkdep_usetex + return checkdep_usetex(True) + except ImportError: + print("This function is not available, you may be missing matplotlib.") + + +_gudhi_matplotlib_use_tex = _matplotlib_can_use_tex() + def __min_birth_max_death(persistence, band=0.0): """This function returns (min_birth, max_death) from the persistence. @@ -57,17 +71,6 @@ def _array_handler(a): else: return a -@lru_cache(maxsize=1) -def _matplotlib_can_use_tex(): - """This function returns True if matplotlib can deal with LaTeX, False otherwise. - The returned value is cached. - """ - try: - from matplotlib import checkdep_usetex - return checkdep_usetex(True) - except ImportError: - print("This function is not available, you may be missing matplotlib.") - def plot_persistence_barcode( persistence=[], @@ -117,10 +120,13 @@ def plot_persistence_barcode( try: import matplotlib.pyplot as plt import matplotlib.patches as mpatches - if _matplotlib_can_use_tex(): - from matplotlib import rc + from matplotlib import rc + if _gudhi_matplotlib_use_tex: plt.rc('text', usetex=True) plt.rc('font', family='serif') + else: + plt.rc('text', usetex=False) + plt.rc('font', family='DejaVu Sans') if persistence_file != "": if path.isfile(persistence_file): @@ -263,10 +269,13 @@ def plot_persistence_diagram( try: import matplotlib.pyplot as plt import matplotlib.patches as mpatches - if _matplotlib_can_use_tex(): - from matplotlib import rc + from matplotlib import rc + if _gudhi_matplotlib_use_tex: plt.rc('text', usetex=True) plt.rc('font', family='serif') + else: + plt.rc('text', usetex=False) + plt.rc('font', family='DejaVu Sans') if persistence_file != "": if path.isfile(persistence_file): @@ -436,10 +445,13 @@ def plot_persistence_density( import matplotlib.pyplot as plt import matplotlib.patches as mpatches from scipy.stats import kde - if _matplotlib_can_use_tex(): - from matplotlib import rc + from matplotlib import rc + if _gudhi_matplotlib_use_tex: plt.rc('text', usetex=True) plt.rc('font', family='serif') + else: + plt.rc('text', usetex=False) + plt.rc('font', family='DejaVu Sans') if persistence_file != "": if dimension is None: |