Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Slicer matplotlib-warning. #217

Merged
merged 2 commits into from
Sep 2, 2020
Merged

Fix Slicer matplotlib-warning. #217

merged 2 commits into from
Sep 2, 2020

Conversation

prisae
Copy link
Member

@prisae prisae commented Jul 29, 2020

Closes #215

@prisae prisae requested a review from jcapriot July 29, 2020 07:17
@prisae
Copy link
Member Author

prisae commented Jul 29, 2020

What I am not sure about is... I think I included clim as a parameter because it is also there in plotSlice and plotImage. However, this way it can be provided as clim but as well in pcolor_opts. Not sure if it would be better to deprecate clim, and push the use of pcolor_opts, to make the discretize-code slimmer and leave these things to matplotlib?

What is your @jcapriot, @lheagy ?

@codecov
Copy link

codecov bot commented Jul 29, 2020

Codecov Report

Merging #217 into master will increase coverage by 0.01%.
The diff coverage is 90.90%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #217      +/-   ##
==========================================
+ Coverage   81.39%   81.41%   +0.01%     
==========================================
  Files          24       24              
  Lines        5197     5202       +5     
==========================================
+ Hits         4230     4235       +5     
  Misses        967      967              
Impacted Files Coverage Δ
discretize/View.py 70.83% <90.90%> (+0.16%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a4ead91...a0edf08. Read the comment docs.

@prisae
Copy link
Member Author

prisae commented Jul 30, 2020

That needs more testing, because vmin/vmax are log if the norm is log... so the current version will fail. I think we need to talk about this, and maybe get rid of clim to simplify things.

@prisae
Copy link
Member Author

prisae commented Aug 1, 2020

Good to go and ready for review. Works also with norms.

I made another small change. We should not patch matplotlib, and propagate deprecation warnings. We should simply not cause matplotlib errors.

So now, these two possibilities run without warnings:

mesh.plot_3d_slicer(res, pcolor_opts={'norm': LogNorm(vmin=0.3, vmax=200)})

and

mesh.plot_3d_slicer(np.log10(res), clim=[np.log10(0.3), np.log10(200)])

and these two cases will raise a matplotlib deprecation warning, because they should be adjusted (to the above versions):

mesh.plot_3d_slicer(res, clim=[0.3, 200], pcolor_opts={'norm': LogNorm()})

and

mesh.plot_3d_slicer(res, clim=[0.3, 10], pcolor_opts={'norm': LogNorm(vmin=0.3, vmax=200)})

Here a minimum working example to test:

import warnings
import discretize
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LogNorm
from matplotlib.cbook import MatplotlibDeprecationWarning

# ALWAYS SHOW THE MATPLOTLIB WARNINGS
warnings.simplefilter('always', MatplotlibDeprecationWarning)

mesh = discretize.TensorMesh([5, 1, 1])
res = 10**np.arange(5)

# 1: Good: Provide vmin/vmax in the norm
mesh.plot_3d_slicer(res, pcolor_opts={'norm': LogNorm(vmin=1, vmax=1000)})

# 2: Good: Provide clim, but NO norm
mesh.plot_3d_slicer(np.log10(res), clim=[0, 3])

# 3: Deprecated: Provide clim with a norm (new deprecated since matplotlib 3.3) 
mesh.plot_3d_slicer(res, clim=[1, 1000], pcolor_opts={'norm': LogNorm()})

# 4: Deprecated: Provide clim with a norm AND norm-v{min;max} (new deprecated since matplotlib 3.3) 
mesh.plot_3d_slicer(res, clim=[1, 1000], pcolor_opts={'norm': LogNorm(vmin=1, vmax=1000)})

Copy link
Member

@jcapriot jcapriot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good for the slicer

@jcapriot jcapriot merged commit 9c68f9e into simpeg:master Sep 2, 2020
@prisae prisae deleted the slicer-fix-matplotlib-warning branch September 2, 2020 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

matplotlib deprecated passing norm and vmin/vmax simultaneously.
2 participants