2

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()

This gives the following plot:

enter image description here

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.

Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174
  • This seems to be a bug, which is still present in the current development version. Would you like to open an issue about it [on the GitHub issue tracker](https://github.com/matplotlib/matplotlib/issues)? – ImportanceOfBeingErnest Jul 06 '18 at 12:45
  • Ok thanks for the advice, I have submitted an issue at the Matplotlib GitHub issue tracker: [Missing filled contours when using contourf](https://github.com/matplotlib/matplotlib/issues/11587) – Håkon Hægland Jul 06 '18 at 13:00
  • 1
    It works also if you use `cntr = ax.contourf(x, y, z, extend='max')`. – screenpaver Jul 06 '18 at 13:26

0 Answers0