summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorROUVREAU Vincent <vincent.rouvreau@inria.fr>2020-07-28 14:59:13 +0200
committerROUVREAU Vincent <vincent.rouvreau@inria.fr>2020-07-28 14:59:13 +0200
commit37f806271cc5f00525cbabe0f2ec9db440d455ee (patch)
treef2bc36b35f0ed3961ef2c732d1c765a6dc916f3a /src
parent2bf81f9caa70e30a0e3a8eaf792243a9d4a2436b (diff)
Code review: Do not print warnings on import gudhi
Diffstat (limited to 'src')
-rw-r--r--src/python/gudhi/persistence_graphical_tools.py32
1 files changed, 14 insertions, 18 deletions
diff --git a/src/python/gudhi/persistence_graphical_tools.py b/src/python/gudhi/persistence_graphical_tools.py
index cce091d5..c9c85e46 100644
--- a/src/python/gudhi/persistence_graphical_tools.py
+++ b/src/python/gudhi/persistence_graphical_tools.py
@@ -11,7 +11,6 @@
from os import path
from math import isfinite
import numpy as np
-from functools import lru_cache
from gudhi.reader_utils import read_persistence_intervals_in_dimension
from gudhi.reader_utils import read_persistence_intervals_grouped_by_dimension
@@ -20,20 +19,7 @@ __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()
-
+_gudhi_matplotlib_use_tex = True
def __min_birth_max_death(persistence, band=0.0):
"""This function returns (min_birth, max_death) from the persistence.
@@ -71,6 +57,16 @@ def _array_handler(a):
else:
return a
+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=[],
@@ -121,7 +117,7 @@ def plot_persistence_barcode(
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from matplotlib import rc
- if _gudhi_matplotlib_use_tex:
+ if _gudhi_matplotlib_use_tex and _matplotlib_can_use_tex():
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
else:
@@ -270,7 +266,7 @@ def plot_persistence_diagram(
import matplotlib.pyplot as plt
import matplotlib.patches as mpatches
from matplotlib import rc
- if _gudhi_matplotlib_use_tex:
+ if _gudhi_matplotlib_use_tex and _matplotlib_can_use_tex():
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
else:
@@ -446,7 +442,7 @@ def plot_persistence_density(
import matplotlib.patches as mpatches
from scipy.stats import kde
from matplotlib import rc
- if _gudhi_matplotlib_use_tex:
+ if _gudhi_matplotlib_use_tex and _matplotlib_can_use_tex():
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
else: