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

Merge branch 'matplotlib-fix' into 'master'

Fixed deprecated DivergingNorm -> TwoSlopeNorm

See merge request !39
parents 7f40b76f 88377a32
Branches master
No related tags found
No related merge requests found
Pipeline #51665 failed
......@@ -24,7 +24,7 @@ dependencies:
- hyperspy-gui-ipywidgets=1.2
#- h5py=2.9 # TODO: dependency of hyperspy? Not needed here?
# Plotting and colors:
- matplotlib=3.1
- matplotlib=3.2
- Pillow=6.1
- cmocean=2.0
# 3D plotting:
......
......@@ -40,7 +40,7 @@ setup_requires =
setuptools
install_requires =
numpy >= 1.17
matplotlib >= 3
matplotlib >= 3.2
scikit-image
tqdm
scipy
......
......@@ -10,7 +10,7 @@ import warnings
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import DivergingNorm
from matplotlib.colors import TwoSlopeNorm
from PIL import Image
from . import colors
......@@ -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):
cmap = plt.get_cmap(cmap)
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):
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))
# Plot with the empyre style context:
with use_style('empyre-image'): # Only works on axes created WITHIN context!
......@@ -191,7 +192,8 @@ def colorvec(field, axis=None, **kwargs):
cmap = colors.cmaps.cyclic_cubehelix
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):
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))
# Plot with the empyre style 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):
contours += 1 # Shift to positive values
contours /= 2 # Rescale to [0, 1]
# 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))
# Plot with the empyre style 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