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

BUG: symlog colorbar with linear threshold < vmin + matplotlib 3.5 #3564

Closed
neutrinoceros opened this issue Oct 13, 2021 · 1 comment · Fixed by #3565
Closed

BUG: symlog colorbar with linear threshold < vmin + matplotlib 3.5 #3564

neutrinoceros opened this issue Oct 13, 2021 · 1 comment · Fixed by #3565
Milestone

Comments

@neutrinoceros
Copy link
Member

Bug report

Bug summary

Code for reproduction

import matplotlib
import numpy as np
import yt

prng = np.random.RandomState(0)
d = {'my_fake_density': prng.random_integers(1, 3, size=(64,64,64))}

ds = yt.load_uniform_grid(d, [64,64,64])
p = yt.SlicePlot(ds, "z", ('stream', 'my_fake_density'))
p.set_log(('stream', 'my_fake_density'), True, linthresh=1.e-3)
p.save(f"/tmp/mpl_{matplotlib.__version__}_")

Actual outcome
mpl_3 5 0rc1__Slice_z_my_fake_density

Expected outcome
This is the result of the same script, using matplotlib 3.4.3
mpl_3 4 3__Slice_z_my_fake_density

Arguably, the behaviour with MPL 3.4 can be considered canonical, but maybe we need to add a warning when the value of linthresh is under the actual minimum value.

I note that this reference behaviour, setting the lower limit of the colobar to the data's minimum rather than the user required linthresh, is in line with what can be obtained in both matplotlib 3.4 and 3.5 without yt:

import matplotlib.pyplot as plt
from matplotlib.colors import SymLogNorm
import matplotlib
import numpy as np

prng = np.random.RandomState(0)
data = prng.random_integers(1, 3, size=(64,64))

fig, ax = plt.subplots()
im = ax.imshow(data, norm=SymLogNorm(linthresh=1e-2))
cb = fig.colorbar(im)
file = f"/tmp/threshold_mpl_{matplotlib.__version__}.png"
fig.savefig(file)

gives
threshold_mpl_3 4 3

@neutrinoceros
Copy link
Member Author

The fix is likely along the lines of preventing the norm class to be set to SymLogNorm when it doesn't make sense, do it as early as possible, and emit a warning.
I'll give it a go later

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant