Skip to content

plot_surface with facecolors distorts colors due to default shading=True #30290

@MisoNyang-i

Description

@MisoNyang-i

Summary

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.colors import Normalize

X = np.linspace(0, 1, 100)
Y = np.linspace(0, 1, 100)
X_mesh, Y_mesh = np.meshgrid(X, Y)
Z =  np.cos((1-X_mesh) * np.pi)*np.cos((1-Y_mesh) * np.pi)*1e+14 + 1.4e+15
Z_colors = np.cos(X_mesh * np.pi)

norm = Normalize(vmin=np.min(Z_colors), vmax=np.max(Z_colors))
colors = cm.gist_heat_r(norm(Z_colors))[:-1, :-1]

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X_mesh, Y_mesh, Z, facecolors=colors, edgecolor='none')
plt.show()

Proposed fix

fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(X_mesh, Y_mesh, Z, facecolors=colors, edgecolor='none', shade=False)
plt.show()

When colors represent actual data values, shading-induced distortion is critical.

  1. If facecolors is explicitly given, shade=False should be the default behavior, since the user is already controlling the color manually.
  2. Alternatively, at minimum, this behavior should be clearly documented in the plot_surface API page, warning users that shading will distort manually specified facecolors.
  3. Or, provide an explicit warning if both facecolors and shade=True are used together.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy