问题
I am trying to plot a 3D dataset using the contourf function in matplotlib.pyplot. All of this is being run inside an iPython notebook. A surface plot of the data looks fine, but the contourf plot has a big hole in it.
A simplified version of the code I am using is:
import numpy as np # import modules
import scipy.io as spio
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure(figsize=(12,5))
zMin = 1.2
data = spio.loadmat('./OD_SurfMatFiles/surf_k2_c3.mat')
X = data['xVal']
Y = data['yVal']
Z = data['zVal']
plotX, plotY = numpy.meshgrid(X, Y)
ax = fig.add_subplot(1,2,1, projection='3d')
colourLevels = [0.0, 0.4, 0.8, 1.2, 1.6, 2.0, 2.4];
cset = ax.contourf(plotX, plotY, Z, colourLevels, zdir='z',offset=zMin, cmap=cm.autumn)
CB = plt.colorbar(cset, shrink=0.5, extend='both')
The result can be seen here:
http://nbviewer.ipython.org/url/www.alexbaldwin.org.uk/pynotebooks/OD%2520Appendix%2520HM%2520Noise%2520Aperture%2520SurfBug%2520MWE%25202.ipynb
The data that is being plotted is exported from MATLAB:
xVal =
384 416 448 480 512 544 576 608 640 672
yVal =
18 19 20 21 22
zVal =
Columns 1 through 9
1.1717 1.1421 1.1358 1.2124 1.1721 1.1840 1.1809 1.1399 1.1708
1.1286 1.2183 1.1654 1.1675 1.1810 1.1745 1.2100 1.2284 1.2096
1.2132 1.3057 1.2616 1.1742 1.2639 1.2316 1.2039 1.2277 1.2367
1.2363 1.1987 1.2367 1.2171 1.2718 1.2040 1.2462 1.1802 1.2218
1.2230 1.2601 1.2411 1.2436 1.2635 1.2197 1.2300 1.2266 1.2368
Column 10
1.2357
1.2039
1.3010
1.2273
1.2336
I originally had this problem with matplotlib 1.2. I considered that they may have fixed it in a later version, but even with u'1.4.x' it still occurs.
来源:https://stackoverflow.com/questions/18897950/matplotlib-pyplot-contourf-function-introduces-holes-or-gaps-when-plotting-regul