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

Color of Contour lines in Surfaces with colormap are not correctly set #5006

Open
jparisu opened this issue Feb 2, 2025 · 2 comments
Open
Labels
bug something broken P3 backlog

Comments

@jparisu
Copy link

jparisu commented Feb 2, 2025

I think there is an issue in the way the lines plot by a contours in a Surface object when selecting the color.
I think the color is not being correctly selected by each of the lines. They are supposed to follow the colorscale, but they just follows half of it.

Here there is a minimum example of code to simulate the error:

import numpy as np
import plotly.graph_objects as go

x = np.linspace(0, 1, 100)
y = np.linspace(0, 1, 100)
x_grid, y_grid = np.meshgrid(x, y)

z = x_grid + y_grid

params = {
    'colorscale': 'rainbow',
    'surfacecolor': z,
    'showscale': True,
    'colorbar': {
        'title': 'z',
    },
    'contours_z': {
        'show': True,
        'usecolormap': True,
        "project_z": True,
    }
}

trace = go.Surface(
    x=x,
    y=y,
    z=z,
    **params)

fig = go.Figure(data=[trace])
fig.write_image("test.png")
fig.show()

In the example, the expected behavior will be for the contour lines to be the same color as the surface, but they are not.

Image

@jparisu
Copy link
Author

jparisu commented Feb 2, 2025

I just realized the parameter surfacecolor is not needed, and removing it fixes the problem.
However, I still wonder why if z=surfacecolor the result is not the same as removing surfacecolor.

Update

Also, I am encountering some strange behavior, as if I remove surfacecolor I get the correct surface, but the parameter usecolormap from contours_z does not longer apply and the color of the lines is always the same when having 2 surfaces in the same plot (with only one as the example it seems like it does not happen).

@gvwilson gvwilson added bug something broken P3 backlog labels Feb 3, 2025
@gvwilson
Copy link
Contributor

gvwilson commented Feb 3, 2025

Thanks for the bug report @jparisu - can you please post your note about strange behavior in our forum (https://community.plotly.com/) to see if someone there has a fix? (Realistically, it's going to be a while before we can look at it…) Thanks - @gvwilson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug something broken P3 backlog
Projects
None yet
Development

No branches or pull requests

2 participants