Two 3d surface with different color map

Hi,
I looked at “Multiple 3D Surface Plots” . I want to know if we can construct two 3d surface with different color maps in one layout. Color bar will be associated with just one of two layers?
Please let me know.
Regards

Hi @doga,

Each surface trace can have its own colorscale using the colorscale property. And colorbars can be disabled for all but one by setting the showscale property to False. For example:

import plotly.graph_objs as go
from plotly.offline import iplot, init_notebook_mode
init_notebook_mode()


z1 = [
    [8.83,8.89,8.81,8.87,8.9,8.87],
    [8.89,8.94,8.85,8.94,8.96,8.92],
    [8.84,8.9,8.82,8.92,8.93,8.91],
    [8.79,8.85,8.79,8.9,8.94,8.92],
    [8.79,8.88,8.81,8.9,8.95,8.92],
    [8.8,8.82,8.78,8.91,8.94,8.92],
    [8.75,8.78,8.77,8.91,8.95,8.92],
    [8.8,8.8,8.77,8.91,8.95,8.94],
    [8.74,8.81,8.76,8.93,8.98,8.99],
    [8.89,8.99,8.92,9.1,9.13,9.11],
    [8.97,8.97,8.91,9.09,9.11,9.11],
    [9.04,9.08,9.05,9.25,9.28,9.27],
    [9,9.01,9,9.2,9.23,9.2],
    [8.99,8.99,8.98,9.18,9.2,9.19],
    [8.93,8.97,8.97,9.18,9.2,9.18]
]

z2 = [[zij+1 for zij in zi] for zi in z1]
z3 = [[zij-1 for zij in zi] for zi in z1]

data = [
    go.Surface(z=z1, colorscale='Electric', showscale=False),
    go.Surface(z=z2, opacity=0.9, colorscale='Viridis', showscale=True),
    go.Surface(z=z3, opacity=0.9, colorscale='Blues', showscale=False)

]

iplot(data)

Hope that helps!
-Jon

1 Like

Hi,
Thank you for your previous help.

I am working on it.
What if z2 has smaller x_axis, and y_axis within z1, how can I construct the surfaces.

For example:
I have 3d topographical surface which contains some landslides that have smaller x, y extends.

Also, I need to know:
for each landslide surface, Do I need separate surfaces ?

regards

Hi @doga,

What if z2 has smaller x_axis, and y_axis within z1, how can I construct the surfaces.

You can use the x and y properties to control the x/y range of the surface.

import plotly.graph_objs as go
from plotly.offline import iplot, init_notebook_mode
init_notebook_mode()


z1 = [
    [8.83,8.89,8.81],
    [8.89,8.94,8.85],
    [8.84,8.9,8.82]
]

z2 = [[zij+1 for zij in zi] for zi in z1]
z3 = [[zij-1 for zij in zi] for zi in z1]

data = [
    go.Surface(z=z1, x=[3, 5, 7], y=[3, 5, 7], colorscale='Electric', showscale=False),
    go.Surface(z=z2, x=[4, 5, 6], y=[4, 5, 6], opacity=0.9, colorscale='Viridis', showscale=True),
    go.Surface(z=z3, x=[1, 5, 10], y=[1, 5, 10], opacity=0.9, colorscale='Blues', showscale=False)]
iplot(data)

In this example z1, z2, and z3 all have the same size, but this doesn’t need to be the case.

for each landslide surface, Do I need separate surfaces ?

Hmm, I don’t think you can have a single surface trace represent multiple disjoint regions so you may need to use a separate trace per landslide. On the other hand. you might be able to fake it with one surface by dropping the elevation below the land for the regions in between landslides.

Hope that helps!
-Jon

Actually, there is a way. If you set the z value to np.nan then you can remove portions of the surface

import plotly.graph_objs as go
from plotly.offline import iplot, init_notebook_mode
init_notebook_mode()
import numpy as np

z1 = [
    [8.83,8.89,np.nan],
    [8.89,8.94,8.85],
    [8.84,8.9,8.82]
]

z2 = [[zij+1 for zij in zi] for zi in z1]
z3 = [[zij-1 for zij in zi] for zi in z1]

data = [
    go.Surface(z=z1, x=[3, 5, 7], y=[3, 5, 7], colorscale='Electric', showscale=False),
    go.Surface(z=z2, x=[4, 5, 6], y=[4, 5, 6], opacity=0.9, colorscale='Viridis', showscale=True),
    go.Surface(z=z3, x=[1, 5, 10], y=[1, 5, 10], opacity=0.9, colorscale='Blues', showscale=False)]
iplot(data)

-Jon