[New-bugs-announce] [issue45422] Data 0 cannot be plotted by matplotlib.pyplot just because some data is less than 0. (ContourSet._get_lowers_and_uppers)

Jianke SHI report at bugs.python.org
Sun Oct 10 06:19:58 EDT 2021


New submission from Jianke SHI <shi.jianke.xhdre at showadenko.com>:

Data 0 cannot be plotted by matplotlib.pyplot(3.3.4) just because some data is less than 0 (python 3.8.8).

The following is a sample program to confirm the problem.
the left-bottom area in the right figure is not colored and remains transparent just because the data z[2,2] is changed from 0 to -1.7E-13.
(see attached png file.)


I tried to trace the problem and find that the reason seems to be a bug in ContourSet._get_lowers_and_uppers.(Line 1065 in contour.py(3.3.4))

        if self.zmin == lowers[0]:
            # Include minimum values in lowest interval
            lowers = lowers.copy()  # so we don't change self._levels
            if self.logscale:
                lowers[0] = 0.99 * self.zmin
            else:
                lowers[0] -= 1

while lowers[0] is the same as self.zmin, it will be reduced a little before using. However, while lowers[0] is greater than self.zmin ( = -1.7E-13 ), it will not be reduced and remains as it is.
I think the condition should be revised to self.zmin <= lowers[0]
 from self.zmin == lowers[0]. 

(sample program)

import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

z0 = np.array([[0., 0., 2.], [0., 0., 1.], [2., 1., 0.]])
z1 = np.array([[0., 0., 2.], [0., 0., 1.], [2., 1., -1.7E-13]])

fig = plt.figure(figsize=(2, 4))

ax0 = fig.add_subplot(121)
ax0.contourf(z0, cmap='jet')
ax0.set_aspect('equal')

ax1 = fig.add_subplot(122)
ax1.contourf(z1, cmap='jet')
ax1.set_aspect('equal')

plt.show()

----------
components: Library (Lib)
files: test_contourf_jet4r.png
messages: 403579
nosy: Klam
priority: normal
severity: normal
status: open
title: Data 0 cannot be plotted by matplotlib.pyplot just because some data is less than 0. (ContourSet._get_lowers_and_uppers)
type: behavior
versions: Python 3.7, Python 3.8
Added file: https://bugs.python.org/file50337/test_contourf_jet4r.png

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45422>
_______________________________________


More information about the New-bugs-announce mailing list