If I attempt to make a contour plot with data that is entirely below the lowest level, and the data has a field of zeros around it, I get an unexpected contour between the zeros and anything positive.
I've confirmed that this is a bug. If the levels for a line contour plot are all outside of the z limits, the levels are replaced by the lower z limit, here:
Under most circumstances we'd get away with this behaviour. However, if there is a quad which has the lower-z value on 3 of its 4 corners then half the area of the quad is at the lower level and the contour line is calculated on the upper edge of this triangle (see #19691 for detailed explanation).
I presume that if the user specifies the contour levels then we should not modify them, even if this means that no contour lines are plotted. But I suspect there may be issues about colorbars being displayed without any contents?
Thanks @ianthomas23 for taking a look at this and providing an explanation. With this knowledge we can make a simple workaround in the user code by setting a new, artificial, localised minimum before plotting. E.g.
Activity
ianthomas23 commented on May 11, 2021
I've confirmed that this is a bug. If the levels for a line contour plot are all outside of the z limits, the levels are replaced by the lower z limit, here:
matplotlib/lib/matplotlib/contour.py
Lines 1141 to 1147 in a9c5224
Here is a simple reproducer:
Under most circumstances we'd get away with this behaviour. However, if there is a quad which has the lower-z value on 3 of its 4 corners then half the area of the quad is at the lower level and the contour line is calculated on the upper edge of this triangle (see #19691 for detailed explanation).
I presume that if the user specifies the contour levels then we should not modify them, even if this means that no contour lines are plotted. But I suspect there may be issues about colorbars being displayed without any contents?
rcomer commented on May 16, 2021
Thanks @ianthomas23 for taking a look at this and providing an explanation. With this knowledge we can make a simple workaround in the user code by setting a new, artificial, localised minimum before plotting. E.g.