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

plt.contour levels parameter don't work as intended if receive a single int #11913

Copy link
Copy link
Closed
@eisterman

Description

@eisterman
Issue body actions

Bug report

Bug summary

The official documentation (https://matplotlib.org/api/_as_gen/matplotlib.pyplot.contour.html) says that the parameter levels of the pyplot.contour function is an integer will be calculated and shown a number of contours equal to the number passed as a parameter.
The reality of the facts, however, is that the outline associated with the past value is plotted.

Code for reproduction

I used the contour demo example from https://matplotlib.org/gallery/images_contours_and_fields/contour_demo.html#contour-demo adding the levels parameter as int.

import matplotlib
import numpy as np
import matplotlib.cm as cm
import matplotlib.pyplot as plt

delta = 0.025
x = np.arange(-3.0, 3.0, delta)
y = np.arange(-2.0, 2.0, delta)
X, Y = np.meshgrid(x, y)
Z1 = np.exp(-X**2 - Y**2)
Z2 = np.exp(-(X - 1)**2 - (Y - 1)**2)
# the original demo had 2 here, but so most of the values would have been less than 5
Z = (Z1 - Z2) * 6

plt.contour(X, Y, Z, levels=5)
plt.show()

Actual outcome

Output_bug_1

Expected outcome

According to official documentation I should expect 5 outlines and not the boundary associated with the value 5.
Right_outcome_1

The expected output was obtained by modifying the penultimate line in:

plt.contour(X, Y, Z, levels=np.linspace(np.min(Z),np.max(Z),7))

Matplotlib version

  • Operating system: Arch Linux
  • Matplotlib version: 2.2.3
  • Matplotlib backend (print(matplotlib.get_backend())): Qt5Agg
  • Python version: 3.7.0
  • Other libraries: numpy

All libraries have been installed via the official ArchLinux repository

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

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.