Skip to content

matplotlib 3D surface - gaps / holes in surface #8222

Closed
@fmevers

Description

@fmevers

Bug report

Bug summary

A grid is interpolated with scipy's griddata() and contains values and NaNs. However, when the grid is plotted with mplot3d's plot_surface() there are gaps in the surface (see upper plot). The lower the view height, the more of such gaps are rendered. When the grid is plotted in 2D with imshow() there are no gaps (see lower plot).

Code for reproduction

import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D

Z = np.loadtxt('data.txt')
X = np.linspace(0,3,301)
Y = np.linspace(0,3,301)
X = np.array([X,]*(301)).transpose()
Y = np.array([Y,]*(301))
fig = plt.figure(figsize=(15,15), dpi=100)
ax = fig.add_subplot(2, 1, 1, projection='3d')
ax.view_init(40,300)
surf = ax.plot_surface(X, Y, Z, cmap='jet', rstride=1, cstride=1, antialiased=False, shade=False, alpha=1.0, linewidth=0, vmin=0.25, vmax=0.35);

ax.invert_yaxis()
ax.dist = 11

ax = fig.add_subplot(2, 1, 2)
plt.imshow(Z, cmap='jet', vmin=0.25, vmax=0.35, origin='lower');

plt.show()

Actual outcome


Close-up:

Expected outcome

No holes in the 3D surface plot.

Matplotlib version

Matplotlib 1.3.0 to 1.5.3 (WinPython 3.3.2.3 to 3.5.2.3), but it was also reproduced up to Matplotlib 2.0: http://stackoverflow.com/questions/41268550/matplotlib-3d-surface-gaps-holes-in-surface

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions