Skip to content

Commit

Permalink
Deal with matplotlib 3.6 deprecation/rename of seaborn-colorblind
Browse files Browse the repository at this point in the history
Matplotlib changed the name of our default colour theme (presumably to
be future-proof against defaults of later seaborn versions?)
  • Loading branch information
ajjackson committed Oct 7, 2024
1 parent 2a29b92 commit 34d7a66
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Versioning <http://semver.org/>`__. The changelog format is inspired by

`Unreleased <https://github.com/smtg-ucl/galore/compare/0.9.0...HEAD>`__
-------------------------------------------------------------------------
- Deal with matplotlib 3.6 deprecation/rename of seaborn-colorblind (@ajjackson)


`[0.9.0] <https://github.com/smtg-ucl/galore/compare/0.8.0...0.9.0>`__ - 2023-08-14
-----------------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions galore/cli/galore.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import numpy as np

import galore
from galore.cli.utils import get_default_style
import galore.formats
import galore.plot
from galore import auto_limits
Expand Down Expand Up @@ -287,9 +288,9 @@ def get_parser():
parser.add_argument(
'--ymax', type=float, default=None, help='Maximum y axis value')
parser.add_argument(
'--style', type=str, nargs='+', default=['seaborn-colorblind'],
'--style', type=str, nargs='+', default=get_default_style(),
help='Plotting style: a sequence of matplotlib styles and paths to '
'style files. The default palette is called "seaborn-colorblind".'
'style files.'
)
parser.add_argument(
'--overlay', type=str, default=None, help='Data file for overlay')
Expand Down
9 changes: 4 additions & 5 deletions galore/cli/galore_plot_cs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
import logging
import numpy as np
from matplotlib import pyplot as plt
plt.style.use('seaborn-colorblind')

from galore.cli import get_default_style
from galore.cross_sections import get_cross_sections_scofield


Expand All @@ -52,9 +52,9 @@ def get_parser():
parser.add_argument('--fontsize', type=int, default=12,
help="Font size in pt")
parser.add_argument(
'--style', type=str, nargs='+', default=['seaborn-colorblind'],
'--style', type=str, nargs='+', default=get_default_style(),
help='Plotting style: a sequence of matplotlib styles and paths to '
'style files. The default palette is called "seaborn-colorblind".'
'style files.'
)
parser.add_argument('elements', type=str, nargs='+', help="""
Space-separated symbols for elements in material.""")
Expand All @@ -67,8 +67,7 @@ def run(elements, emin=1, emax=10, megabarn=False, size=None, output=None,
energies = np.linspace(emin, emax, 200)
cross_sections = get_cross_sections_scofield(energies, elements)

if style is not None:
plt.style.use(style)
plt.style.use(style)

if size is None:
fig = plt.figure()
Expand Down
12 changes: 12 additions & 0 deletions galore/cli/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""Utility functions used by command-line tools"""

import matplotlib
from packaging.version import Version

def get_default_style() -> str:
"""Get appropriate name for seaborn-colorblind, depending on MPL version"""

if Version(matplotlib) < Version("3.6"):
return "seaborn-colorblind"

return "seaborn-v0_8-colorblind"
4 changes: 2 additions & 2 deletions galore/plot.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Plotting routines with Matplotlib"""
from collections import defaultdict
from os.path import basename as path_basename
from itertools import cycle
from os.path import basename as path_basename
import logging

import numpy as np
from matplotlib import pyplot as plt
import numpy as np

from galore import auto_limits
import galore.formats
Expand Down

0 comments on commit 34d7a66

Please sign in to comment.