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

Confusion about the number of contour levels #4537

Copy link
Copy link
Closed
@mwaskom

Description

@mwaskom
Issue body actions

According to the docstring, plt.contour(X, Y, Z, N) should "contour N automatically-chosen levels".

The actual results are somewhat surprising:

import numpy as np
import matplotlib.pyplot as plt

np.random.seed(0)
xx, yy = np.mgrid[-3:3:, -3:3]

for _ in xrange(10):
    zz = np.random.randn(6, 6)
    cset = plt.contour(xx, yy,  zz, 9)
    print(len(cset.levels)),

prints 9 9 8 8 9 9 8 8 9 9.

Additionally, the docstring for plt.contourf has the same prose, but adds some more confusing behavior:

for _ in xrange(10):
    zz = np.random.randn(6, 6)
    cset = plt.contourf(xx, yy,  zz, 9)
    print(len(cset.levels)),

prints 11 10 11 10 10 11 10 11 11 11 (note that the N is the same as for the contour call above).

Am I missing something, or is this is a bug?

mathurinm

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.