Skip to content

Missing filled contours when using contourf #11587

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
hakonhagland opened this issue Jul 6, 2018 · 4 comments · Fixed by #11591
Closed

Missing filled contours when using contourf #11587

hakonhagland opened this issue Jul 6, 2018 · 4 comments · Fixed by #11591
Assignees
Milestone

Comments

@hakonhagland
Copy link

I am trying to plot plot a function over a 2D domain using contourf. Unfortunately, my first attempt did not work out very well. There was a region in the plot that was unexpectedly not covered by any contours. For debugging purposes, I have reduced the problem to the smallest dataset that I could find that also reveals the issue with missing filled contours:

import matplotlib.pyplot as plt
import numpy as np

v = np.array([0, 1, 2, 3])
x, y = np.meshgrid(v, v)

z = np.array([[5.5e-14, 5.5e-14, 5.5e-14, 5.5e-14],
              [2e-13, 2e-13, 2e-13, 2e-13],
              [2.2e-13, 2.2e-13, 2.2e-13, 2.2e-13],
              [0, 0,0, 0]])
fig, ax = plt.subplots()
cntr = ax.contourf(x, y, z)
fig.colorbar(cntr, ax=ax)
plt.show()

figure_1

as you can see there are missing contours from y = 1.5 to approximately y = 2.0.

Another strange thing I observed: If I normalize the z matrix by multiplying by e.g. 1e14 before plotting it works fine.

Matplotlib version

  • Operating system: Ubuntu 18.04
  • Matplotlib version: 2.2.2 (Installed with pip)
  • Matplotlib backend: TkAgg
  • Python version: 3.6.1

Note: This question was first asked on stackoverflow.com: Missing filled contours when using contourf

@jklymak
Copy link
Member

jklymak commented Jul 6, 2018

What happens if you specify the contour levels manually?

Seems like a roundoff error, but I’m not sure

@jklymak
Copy link
Member

jklymak commented Jul 6, 2018

manual contours work fine. I can reproduce otherwise. @efiring not sure how this fits in w/ #11412?

@jklymak jklymak added this to the v2.2.3 milestone Jul 6, 2018
@efiring
Copy link
Member

efiring commented Jul 6, 2018

It's unrelated to #11412. It is only peripherally related to contourf; the problem is in MaxNLocator. I can track it down today.

@efiring efiring self-assigned this Jul 6, 2018
@efiring
Copy link
Member

efiring commented Jul 6, 2018

As a side note, there can be other problems with using very small or very large numbers in mpl, and they also lead to potentially confusing labeling of the colorbar, so I recommend that people scale their units before plotting. E.g., if the range is a few micrograms, plot and label with micrograms, not kilograms.

efiring added a commit to efiring/matplotlib that referenced this issue Jul 6, 2018
efiring added a commit to efiring/matplotlib that referenced this issue Jul 11, 2018
efiring added a commit to efiring/matplotlib that referenced this issue Jul 11, 2018
Closes matplotlib#11587.

Tests were working by accident despite bugs in ticker.Base, but
the bugs caused problems in some applications of MaxNLocator,
as in matplotlib#11587.  Since some user code may be relying on the buggy
behavior, ticker.Base is left in place but deprecated, and its
intended functionality is provided by a new private class,
_Edge_integer.  MaxNLocator and MultipleLocator are modified
to use the new class, with minor cleanups and an additional
bug fix along the way.

Two new relevant test cases are added to TestMaxNLocator.
@jklymak jklymak modified the milestones: v2.2.3, v3.1 Jul 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants