Skip to content

contour edge case with all data below levels and a surrounding field of zeros #20203

Closed
@rcomer

Description

@rcomer

Bug report

Bug summary

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.

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt

y = np.linspace(-10, 10, 20)
x_2d, y_2d = np.meshgrid(y, y)

data = np.cos(x_2d * np.pi/10.) + np.cos(y_2d * np.pi/10.)
np.place(data, data < 0., 0.)

levels = [3, 6]
colors = ['b', 'r']

plt.contour(data, levels=levels, colors=colors)

plt.show()

Actual outcome

bug_zeros_line

Expected outcome

The plot should be blank, which is what happens if the call to np.place is skipped.

Matplotlib version

  • Operating system: RHEL7.9
  • Matplotlib version (import matplotlib; print(matplotlib.__version__)): 3.4.1
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.8.8
  • Jupyter version (if applicable): N/A
  • Other libraries: numpy 1.20.2

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions