Description
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
Expected outcome
According to official documentation I should expect 5 outlines and not the boundary associated with the value 5.
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