Skip to content

Commit

Permalink
matplotlib import fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sspola committed Mar 23, 2022
1 parent dabb87e commit 8158f57
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions simpful/simpful.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
import string
try:
from matplotlib.pyplot import plot, show, title, subplots, legend
try:
import seaborn as sns
except ImportError:
pass
import seaborn as sns
matplotlib = True
except ImportError:
raise Exception("ERROR: please, install matplotlib for plotting facilities")
matplotlib = False

# constant values
linestyles= ["-", "--", ":", "-."]
Expand Down Expand Up @@ -92,6 +90,9 @@ def draw(self, ax, TGT=None, highlight=None):
Returns:
A matplotlib axis, representing all fuzzy sets contained in the liguistic variable.
"""
if matplotlib == False:
raise Exception("ERROR: please, install matplotlib for plotting facilities")

mi, ma = self.get_universe_of_discourse()
x = linspace(mi, ma, 10000)

Expand Down Expand Up @@ -135,6 +136,9 @@ def plot(self, outputfile="", TGT=None, highlight=None):
TGT: show the memberships of a specific element of discourse TGT in the figure.
highlight: string, indicating the linguistic term/fuzzy set to highlight in the plot.
"""
if matplotlib == False:
raise Exception("ERROR: please, install matplotlib for plotting facilities")

fig, ax = subplots(1,1)
self.draw(ax=ax, TGT=TGT, highlight=highlight)

Expand Down Expand Up @@ -696,6 +700,9 @@ def plot_variable(self, var_name, outputfile="", TGT=None, highlight=None, ax=No
highlight: string, indicating the linguistic term/fuzzy set to highlight in the plot.
ax: a matplotlib ax where the variable will be plotted.
"""
if matplotlib == False:
raise Exception("ERROR: please, install matplotlib for plotting facilities")

if ax != None:
ax = self._lvs[var_name].draw(ax=ax, TGT=TGT, highlight=highlight)
return ax
Expand All @@ -710,6 +717,8 @@ def produce_figure(self, outputfile="", max_figures_per_row=4):
outputfile: string containing path and filename where the plot must be saved.
max_figures_per_row: maximum number of figures per row in the plot.
"""
if matplotlib == False:
raise Exception("ERROR: please, install matplotlib for plotting facilities")

num_ling_variables = len(self._lvs)
#print(" * Detected %d linguistic variables" % num_ling_variables)
Expand Down

0 comments on commit 8158f57

Please sign in to comment.