Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[Bug]: Data 0 cannot be plotted by matplotlib.pyplot just because some data is less than 0. #21382

Copy link
Copy link
Open
@JK-SHI

Description

@JK-SHI
Issue body actions

Bug summary

Data 0 cannot be plotted and the corresponding area in the the figure remains transparent, if some data is less than 0.

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].

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

def main():
    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()

if __name__ == "__main__":
    main()

Actual outcome

test_contourf_jet4

the left-bottom area in the right figure is not plotted and remains transparent,
just because the data z[2,2] is changed from 0 to -1.7E-13.

Expected outcome

test_contourf_jet4r

The figure in the right site is expected to be the same as the left one.

Operating system

Windows 10

Matplotlib Version

3.3.4

Matplotlib Backend

module://ipykernel.pylab.backend_inline

Python version

3.8.8

Jupyter version

6.0.1

Other libraries

No response

Installation

conda

Conda channel

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.