Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: plot_surface ignores lightsource when cmap/facecolors are not specified #8877

Open
eric-wieser opened this issue Jul 14, 2017 · 3 comments
Labels
keep Items to be ignored by the “Stale” Github Action topic: mplot3d

Comments

@eric-wieser
Copy link
Contributor

eric-wieser commented Jul 14, 2017

Three different, undocumented, cases that I think should be the same:

  1. plot_surface(..., shade=True, lightsource=..., cmap=..., facecolors="garbage") - uses LightSource.shade, which does some messy and unnecessary trig in LightSource.hillshade, using the orientation of the lightsource.

  2. plot_surface(..., shade=True, lightsource=..., cmap=...) - uses _shade_colors, which does a more sensible vector-based approach, but hard-codes a [-1, -1, 0.5] normal vector, rather than respecting the lightsource direction.

  3. plot_surface(..., shade=True, lightsource=..., facecolors="garbage") - as above

Regarding (2), I think that there is a typo in axes3d.py, and this change should be made:

         # Shade the data
-        if shade and cmap is not None and fcolors is not None:
+        if shade and cmap is not None and fcolors is None:
             fcolors = self._shade_colors_lightsource(Z, cmap, lightsource)

It seems dumb to only calculate face colors if the user already asked for different ones.

Regarding (3) - I think it would be useful to unify the shading into a normal-vector based approach, which I might try in a later patch

@eric-wieser eric-wieser changed the title BUG: plot_surface ignores lightsource when cmap is not specified BUG: plot_surface ignores lightsource when cmap/fcolors are not specified Jul 14, 2017
@eric-wieser
Copy link
Contributor Author

eric-wieser commented Jul 14, 2017

A demo:

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

x, y = np.mgrid[-2:2:5j,-2:2:5j]
z = x * y
  1. Simple case, showing ignored argument:

    fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
    ax.plot_surface(x, y, z, cmap='viridis', shade=True, lightsource='Literally anything')

    image

  2. Showing different shading passing in a unrelated argument. Also, cmap can't always be a string

    fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
    ax.plot_surface(x, y, z, cmap='viridis', shade=True, facecolors="do it differently, ok?")
    # TypeError: String object not callable
    ax.plot_surface(x, y, z, cmap=plt.get_cmap('viridis'), shade=True,
        facecolors="do it differently, ok?")

    image

  3. Showing lightsource calculations being wrong - overhead light should result in symmetric shading:

    from matplotlib.colors import LightSource
    fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
    ax.plot_surface(x, y, z, cmap=plt.get_cmap('viridis'), shade=True,
       facecolors="do it differently, ok?", lightsource=LightSource(altdeg=90))

    image

@eric-wieser eric-wieser changed the title BUG: plot_surface ignores lightsource when cmap/fcolors are not specified BUG: plot_surface ignores lightsource when cmap/facecolors are not specified Jul 14, 2017
@eric-wieser
Copy link
Contributor Author

This should probably remain open until some image-comparison tests are added to confirm it is fixed. I suspect the last issue still persists

@github-actions
Copy link

This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Apr 14, 2023
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 14, 2023
@rcomer rcomer added the status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. label May 30, 2023
@scottshambaugh scottshambaugh added keep Items to be ignored by the “Stale” Github Action and removed status: inactive Marked by the “Stale” Github Action status: closed as inactive Issues closed by the "Stale" Github Action. Please comment on any you think should still be open. labels May 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep Items to be ignored by the “Stale” Github Action topic: mplot3d
Projects
None yet
Development

No branches or pull requests

4 participants