Conditional colormap in 3d surface


#1

Hi,
I need to know if using conditional color mapping in 3d surface Plot is possible?
I want to display 3d surface topography with colormap earth , but certain masked areas with different colormap (black)

Regards


#2

Hi @doga,

You can only have a single color scale per surface, but you can have more control over the coloring by using the surfacecolor property:

Sets the surface color values, used for setting a color scale
independent of `z`.

So you could set surfacecolor to a copy of z with certain regions set to a special value that would change their color. e.g. you could set them to zero.

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

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

surfacecolor = copy.deepcopy(z1)
surfacecolor[0][2] = 0

data = [
    go.Surface(z=z1,
               x=[3, 5, 7],
               y=[3, 5, 7],
               colorscale='Electric',
               surfacecolor=surfacecolor,
               cmin=8.7,
               cmax=8.9,
               showscale=True)
]
iplot(data)

Hope that gives you some ideas :slightly_smiling_face:

-Jon