title: plotly - different color scales for multiple surfaces
body: <p>I am trying to use plotly (4.7.1) with R 3.4.1 to plot two 3D surfaces on the same plot, with two different color scales (variations of blue for one and variations of purple for the other one), and color values derived from z values. When I plot surfaces separately, it works pretty fine, but when I plot both surfaces on the same plot by using add_trace or add_surface, the second surface takes the color of the first one.</p>
  
  <p>Here is an example, using example code from <a href="https://plot.ly/r/3d-surface-plots/#new-to-plotly" rel="nofollow noreferrer">https://plot.ly/r/3d-surface-plots/#new-to-plotly</a></p>
  
  <pre><code>library(plotly)
  
  z &lt;- c(
    c(8.83,8.89,8.81,8.87,8.9,8.87),
    c(8.89,8.94,8.85,8.94,8.96,8.92),
    c(8.84,8.9,8.82,8.92,8.93,8.91),
    c(8.79,8.85,8.79,8.9,8.94,8.92),
    c(8.79,8.88,8.81,8.9,8.95,8.92),
    c(8.8,8.82,8.78,8.91,8.94,8.92),
    c(8.75,8.78,8.77,8.91,8.95,8.92),
    c(8.8,8.8,8.77,8.91,8.95,8.94),
    c(8.74,8.81,8.76,8.93,8.98,8.99),
    c(8.89,8.99,8.92,9.1,9.13,9.11),
    c(8.97,8.97,8.91,9.09,9.11,9.11),
    c(9.04,9.08,9.05,9.25,9.28,9.27),
    c(9,9.01,9,9.2,9.23,9.2),
    c(8.99,8.99,8.98,9.18,9.2,9.19),
    c(8.93,8.97,8.97,9.18,9.2,9.18)
  )
  dim(z) &lt;- c(15,6)
  
  z1 &lt;- z - 1
  z2 &lt;- z + 1
  
  cols1 &lt;- c(rgb(255/255,112/255,183/255,1),rgb(128/255,0/255,64/255,1))
  cols2 &lt;- c(rgb(107/255,184/255,214/255,1),rgb(0/255,90/255,124/255,1))
  
  p1 &lt;- plot_ly(showscale = TRUE) %&gt;%
    add_surface(z = ~z1, cmin = min(z1), cmax = max(z2), color = ~z1, colors = cols1) %&gt;%
    layout(scene = list(zaxis = list(range = c(min(z1),max(z2)))))
  
  p2 &lt;- plot_ly(showscale = TRUE) %&gt;%
    add_surface(z = ~z2, cmin = min(z1), cmax = max(z2), color = ~z2, colors = cols2) %&gt;%
    layout(scene = list(zaxis = list(range = c(min(z1),max(z2)))))
  
  p3 &lt;- plot_ly(showscale = TRUE) %&gt;%
    add_surface(z = ~z1, cmin = min(z1), cmax = max(z2), color = ~z1, colors = cols1) %&gt;%
    add_surface(z = ~z2, cmin = min(z1), cmax = max(z2), color = ~z2, colors = cols2) %&gt;%
    layout(scene = list(zaxis = list(range = c(min(z1),max(z2)))))
  
  p1
  p2
  p3
  </code></pre>
  
  <p>I tried <code>inherit=F</code> into second <code>add_surface</code> but it didn't change anything. I also looked at <a href="https://stackoverflow.com/questions/46150158/plotly-different-colours-for-different-surfaces">plotly - different colours for different surfaces</a>, but the answer does not apply to my case as I don't want uniformely colored plots but colors depending on z values.</p>
  
  <p>I didn't find any answers elsewhere, but I am pretty new to plotly so I hope the answer is not obvious. 
  I somehow managed to get two different scales by using the <code>colorscale</code> argument in the second <code>add_surface</code>: the first surface's colorscale was the default, and the second was different, but not from the colors I defined.</p>
  
  <pre><code>p4 &lt;- plot_ly(showscale = TRUE) %&gt;%
    add_surface(z = ~z1, cmin = min(z1), cmax = max(z2), color = ~z1, reversescale=T) %&gt;%
    add_surface(z = ~z2, cmin = min(z1), cmax = max(z2), color = ~z2, colorscale = list(c(min(z1),"rgb(107,184,214)"),c(max(z2),"rgb(0,90,124)"))) %&gt;%
    layout(scene = list(zaxis = list(range = c(min(z1),max(z2)))))
  
  p4
  </code></pre>
  
  <p>I guess it is somehow manageable because of this last example, but I guess I am doing something wrong here. Any help would be very much appreciated!</p>