You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Missing filled contours when using contourf #11587
I am trying to plot plot a function over a 2D domain using contourf. Unfortunately, my first attempt did not work out very well. There was a region in the plot that was unexpectedly not covered by any contours. For debugging purposes, I have reduced the problem to the smallest dataset that I could find that also reveals the issue with missing filled contours:
import matplotlib.pyplot as plt
import numpy as np
v = np.array([0, 1, 2, 3])
x, y = np.meshgrid(v, v)
z = np.array([[5.5e-14, 5.5e-14, 5.5e-14, 5.5e-14],
[2e-13, 2e-13, 2e-13, 2e-13],
[2.2e-13, 2.2e-13, 2.2e-13, 2.2e-13],
[0, 0,0, 0]])
fig, ax = plt.subplots()
cntr = ax.contourf(x, y, z)
fig.colorbar(cntr, ax=ax)
plt.show()
as you can see there are missing contours from y = 1.5 to approximately y = 2.0.
Another strange thing I observed: If I normalize the z matrix by multiplying by e.g. 1e14 before plotting it works fine.
As a side note, there can be other problems with using very small or very large numbers in mpl, and they also lead to potentially confusing labeling of the colorbar, so I recommend that people scale their units before plotting. E.g., if the range is a few micrograms, plot and label with micrograms, not kilograms.
Activity
jklymak commentedon Jul 6, 2018
What happens if you specify the contour levels manually?
Seems like a roundoff error, but I’m not sure
jklymak commentedon Jul 6, 2018
manual contours work fine. I can reproduce otherwise. @efiring not sure how this fits in w/ #11412?
efiring commentedon Jul 6, 2018
It's unrelated to #11412. It is only peripherally related to contourf; the problem is in
MaxNLocator. I can track it down today.efiring commentedon Jul 6, 2018
As a side note, there can be other problems with using very small or very large numbers in mpl, and they also lead to potentially confusing labeling of the colorbar, so I recommend that people scale their units before plotting. E.g., if the range is a few micrograms, plot and label with micrograms, not kilograms.
BUG: correct the scaling in the floating-point slop test.
BUG: correct the scaling in the floating-point slop test.
BUG: replace buggy ticker.Base with _Edge_integer.