Skip to content
Snippets Groups Projects
Commit 88377a32 authored by Jan Caron's avatar Jan Caron
Browse files

Fixed deprecated DivergingNorm -> TwoSlopeNorm

Needed to raise matplotlib version to 3.2!
parent 7f40b76f
No related branches found
No related tags found
1 merge request!39Fixed deprecated DivergingNorm -> TwoSlopeNorm
...@@ -24,7 +24,7 @@ dependencies: ...@@ -24,7 +24,7 @@ dependencies:
- hyperspy-gui-ipywidgets=1.2 - hyperspy-gui-ipywidgets=1.2
#- h5py=2.9 # TODO: dependency of hyperspy? Not needed here? #- h5py=2.9 # TODO: dependency of hyperspy? Not needed here?
# Plotting and colors: # Plotting and colors:
- matplotlib=3.1 - matplotlib=3.2
- Pillow=6.1 - Pillow=6.1
- cmocean=2.0 - cmocean=2.0
# 3D plotting: # 3D plotting:
......
...@@ -40,7 +40,7 @@ setup_requires = ...@@ -40,7 +40,7 @@ setup_requires =
setuptools setuptools
install_requires = install_requires =
numpy >= 1.17 numpy >= 1.17
matplotlib >= 3 matplotlib >= 3.2
scikit-image scikit-image
tqdm tqdm
scipy scipy
......
...@@ -10,7 +10,7 @@ import warnings ...@@ -10,7 +10,7 @@ import warnings
import numpy as np import numpy as np
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
from matplotlib.colors import DivergingNorm from matplotlib.colors import TwoSlopeNorm
from PIL import Image from PIL import Image
from . import colors from . import colors
...@@ -76,9 +76,10 @@ def imshow(field, axis=None, cmap=None, **kwargs): ...@@ -76,9 +76,10 @@ def imshow(field, axis=None, cmap=None, **kwargs):
elif isinstance(cmap, str): # make sure we have a Colormap object (and not a string): elif isinstance(cmap, str): # make sure we have a Colormap object (and not a string):
cmap = plt.get_cmap(cmap) cmap = plt.get_cmap(cmap)
if cmap.name.replace('_r', '') in DIVERGING_CMAPS: # 'replace' also matches reverted cmaps! if cmap.name.replace('_r', '') in DIVERGING_CMAPS: # 'replace' also matches reverted cmaps!
kwargs.setdefault('norm', DivergingNorm(0)) # Diverging colormap should have zero at the symmetry point! kwargs.setdefault('norm', TwoSlopeNorm(0)) # Diverging colormap should have zero at the symmetry point!
# Set extent in data coordinates (left, right, bottom, top) to kwargs (if not set explicitely): # Set extent in data coordinates (left, right, bottom, top) to kwargs (if not set explicitely):
dim_v, dim_u, s_v, s_u = *squeezed_field.dim, *squeezed_field.scale dim_v, dim_u = squeezed_field.dim
s_v, s_u = squeezed_field.scale
kwargs.setdefault('extent', (0, dim_u * s_u, 0, dim_v * s_v)) kwargs.setdefault('extent', (0, dim_u * s_u, 0, dim_v * s_v))
# Plot with the empyre style context: # Plot with the empyre style context:
with use_style('empyre-image'): # Only works on axes created WITHIN context! with use_style('empyre-image'): # Only works on axes created WITHIN context!
...@@ -191,7 +192,8 @@ def colorvec(field, axis=None, **kwargs): ...@@ -191,7 +192,8 @@ def colorvec(field, axis=None, **kwargs):
cmap = colors.cmaps.cyclic_cubehelix cmap = colors.cmaps.cyclic_cubehelix
rgb = cmap.rgb_from_vector(np.stack((x_comp, y_comp, z_comp), axis=0)) rgb = cmap.rgb_from_vector(np.stack((x_comp, y_comp, z_comp), axis=0))
# Set extent in data coordinates (left, right, bottom, top) to kwargs (if not set explicitely): # Set extent in data coordinates (left, right, bottom, top) to kwargs (if not set explicitely):
dim_v, dim_u, s_v, s_u = *squeezed_field.dim, *squeezed_field.scale dim_v, dim_u = squeezed_field.dim
s_v, s_u = squeezed_field.scale
kwargs.setdefault('extent', (0, dim_u * s_u, 0, dim_v * s_v)) kwargs.setdefault('extent', (0, dim_u * s_u, 0, dim_v * s_v))
# Plot with the empyre style context: # Plot with the empyre style context:
with use_style('empyre-image'): # Only works on axes created WITHIN context! with use_style('empyre-image'): # Only works on axes created WITHIN context!
...@@ -249,7 +251,8 @@ def cosine_contours(field, axis=None, gain='auto', cmap=None, **kwargs): ...@@ -249,7 +251,8 @@ def cosine_contours(field, axis=None, gain='auto', cmap=None, **kwargs):
contours += 1 # Shift to positive values contours += 1 # Shift to positive values
contours /= 2 # Rescale to [0, 1] contours /= 2 # Rescale to [0, 1]
# Set extent in data coordinates (left, right, bottom, top) to kwargs (if not set explicitely): # Set extent in data coordinates (left, right, bottom, top) to kwargs (if not set explicitely):
dim_v, dim_u, s_v, s_u = *squeezed_field.dim, *squeezed_field.scale dim_v, dim_u = squeezed_field.dim
s_v, s_u = squeezed_field.scale
kwargs.setdefault('extent', (0, dim_u * s_u, 0, dim_v * s_v)) kwargs.setdefault('extent', (0, dim_u * s_u, 0, dim_v * s_v))
# Plot with the empyre style context: # Plot with the empyre style context:
with use_style('empyre-image'): # Only works on axes created WITHIN context! with use_style('empyre-image'): # Only works on axes created WITHIN context!
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment