Skip to content

Axes3d plot_surface not supporting masked arrays? #4941

Closed

Description

@maxnoe

Consider this code:

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

fig = plt.figure()
ax = fig.add_subplot(1, 1, 1, projection='3d')

x, y = np.meshgrid(np.linspace(-1, 1), np.linspace(-1, 1))
z = x**2 + y**2

z[10:20, 10:20] = 0.0

masked_array = np.ma.masked_equal(z, 0.0)
palette = cm.gray
palette.set_over('g', 1.0)
palette.set_under('b', 1.0)
palette.set_bad('r', 1.0)

ax.plot_surface(x,y,masked_array,
    rstride=1,
    cstride=1,
    cmap=palette,
    vmin=-1,
    vmax=1,
    )
plt.show()

The area set to zero should be red, but it isn't. It works on a 2d axis using pcolormesh.

Activity

  1. added this to the milestone on Feb 15, 2016
  2. jklymak commented on Jul 8, 2021

    @jklymak
    Member

    As discussed in #18114 I think the mask should apply to the z data, in which case there is no elevation to plot so no colour would be shown.

    If you want an elevation to be plotted, don't mask, and do any of the masking in the colormap, and pass colormapped data facecolor=C, where C = norm(maskedZ)

  3. modified the milestones: , v3.5.0 on Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions