Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

MengAiDev
Copy link
Contributor

@MengAiDev MengAiDev commented Aug 14, 2025

PR summary

  • Update plot_surface function to use "auto" as default shading mode
  • Add tests to verify new shading behavior with different parameters
  • Improve documentation for plot_surface function

Fix: #30290

verify_fix_result

@tacaswell, @story645

- Update plot_surface function to use "auto" as default shading mode
- Add tests to verify new shading behavior with different parameters
- Improve documentation for plot_surface function
Copy link
Contributor

@scottshambaugh scottshambaugh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @MengAiDev, thanks for your first pull request for matplotlib!

I left some comments with some things to change, so leave a comment when you've addressed them and I can take another look. Also please don't hesitate to ask if you have any questions.

i.e. neither *cmap* nor *facecolors* is given.

Furthermore, shading is generally not compatible with colormapping and
``shade=True, cmap=...`` will raise an error.
Copy link
Contributor

@scottshambaugh scottshambaugh Aug 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is not an error being raised in this case AFAICT, so that should be added or this part of the docstring removed. My personal take is that we should not error, and instead warn that colors might not be as expected and still make the plot. @timhoffm thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggested this behavior in #30290 (comment). My argument is that that combination is fundamentally not reasonable because it distorts the mapped colors and thus breaks the purpose of colormapping. If this is our point of view, erroring out is appropriate - prohibit unreasonable things and not just warn that they are unreasonable.

One can take another point of view that the depth-shading is important to get the 3d impression and exact coloring is less important (likely also depends on the colormap used - colormaps that mainly change hue should work better here). If we see this as a valid use case, I would not warn at all at runtime, because the user has to explicitly opt into the behavior by passing both arguments. We then only should add a note to the docstring.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer the latter - there are use cases where colormapping is a visual aid rather than the only display of information, and the shading helps 3D interpretability. The one that I'm thinking about is coloring by Z value.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds reasonable.

Comment on lines +2260 to +2262
# Remove the None check as it doesn't seem to be needed

# Raise error if shade=True and cmap is provided as documented
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# Remove the None check as it doesn't seem to be needed
# Raise error if shade=True and cmap is provided as documented

These comments do note make sense. AFAICS the first is a relic, the second only restates what the code does

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Needs review
Development

Successfully merging this pull request may close these issues.

plot_surface with facecolors distorts colors due to default shading=True
3 participants