Skip to content

Commit

Permalink
Fixed: style names for different matplotlib versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Nyga committed Oct 12, 2023
1 parent 6952084 commit d808e92
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
16 changes: 15 additions & 1 deletion src/jpt/base/constants.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import numpy as np
import matplotlib

sepcomma = ',\n'
sepsemi = ';\n'
Expand Down Expand Up @@ -30,7 +31,20 @@
dred = '#FF4A49ff'

plotcolormap = 'cividis' # or viridis
plotstyle = 'seaborn-deep'


# ----------------------------------------------------------------------------------------------------------------------
# Fix different style names in matplotlib versions
matplotlib_version = matplotlib.__version_info__.major * 10 + matplotlib.__version_info__.minor

if matplotlib_version > 37:
plotstyle = 'seaborn-v0_8-deep'
else:
plotstyle = 'seaborn-deep'


# ----------------------------------------------------------------------------------------------------------------------

avalailable_colormaps = [
'Accent', 'Accent_r', 'Blues', 'Blues_r', 'BrBG', 'BrBG_r', 'BuGn', 'BuGn_r', 'BuPu',
'BuPu_r', 'CMRmap', 'CMRmap_r', 'Dark2', 'Dark2_r', 'GnBu', 'GnBu_r', 'Greens', 'Greens_r',
Expand Down
10 changes: 9 additions & 1 deletion src/jpt/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,19 @@
from .base.functions import PiecewiseFunction


style.use(plotstyle)
try:
style.use(plotstyle)
except OSError:
import logging
logging.warning(
f'Style "{plotstyle}" not found. Falling back to "default".'
)
style.use('default')


# ----------------------------------------------------------------------------------------------------------------------
# Global constants

DISCRIMINATIVE = 'discriminative'
GENERATIVE = 'generative'

Expand Down

0 comments on commit d808e92

Please sign in to comment.