Contour colorscale not set

I am trying to change the colorscale for a contour plot, if I try to use RGB values or preset values (https://github.com/plotly/plotly.js/blob/5bc25b490702e5ed61265207833dbd58e8ab27f1/src/components/colorscale/scales.js) nothing changes, am I missing something?

I have tried copying code directly from an online plot e.g.

colorscale = list(c(0, "rgb(4, 4, 21)"),list(0.35, "rgb(98, 24, 127)"),list(0.5, "rgb(176, 52, 122)"),list(0.6, "rgb(250, 129, 94)"),list(0.7, "rgb(254, 185, 127)"),list(1, "rgb(252, 234, 172)")),

I get this warning in console:

Warning message:
In strip_alpha(traces[[i]]$colorscale[, 2]) :
  Ignoring an alpha value lower than 1

I do not get the warning when using a preset but it still doesn’t work.

Here is the trace part of my script:

p <- plot_ly(x = mydata[[1]],width=1450,height=900)%>%
add_trace(
  y = mydata[[2]],
  z = zdata,
  autocolorscale = FALSE, 
  autocontour = FALSE, 
  colorscale = list(c(0, "rgb(4, 4, 21)"),list(0.35, "rgb(98, 24, 127)"),list(0.5, "rgb(176, 52, 122)"),list(0.6, "rgb(250, 129, 94)"),list(0.7, "rgb(254, 185, 127)"),list(1, "rgb(252, 234, 172)")), 
  connectgaps = TRUE, 
  contours = list(
    coloring = "fill", 
    end = 80, 
    showlines = TRUE, 
    size = 1, 
    start = 60
  ), 
  line = list(
    dash = "solid", 
    width = 0.5
  ), 
  ncontours = 17, 
  opacity = 1, 
  reversescale = FALSE, 
  showscale = TRUE, 
  transpose = TRUE, 
  type = "contour", 
  xtype = "array", 
  ytype = "array", 
  zauto = FALSE, 
  zmax = 200, 
  zmin = 0
)%>%

Can anyone help?

Hi @mrlyule

Hmm perhaps try something like:

p <- plot_ly(
  type = 'contour',
  z=matrix(c(10, 10.625, 12.5, 15.625, 20,
             5.625, 6.25, 8.125, 11.25, 15.625,
             2.5, 3.125, 5., 8.125, 12.5,
             0.625, 1.25, 3.125, 6.25, 10.625,
             0, 0.625, 2.5, 5.625, 10),
           nrow=5, ncol=5),
  colorscale = list(
    c(0,0.5,1),
    c('blue', 'red', 'yellow')
  )
)

Regarding pre-defined colors, it looks like there is an open issue in the R repo. You can follow that here https://github.com/ropensci/plotly/issues/1319

Thanks bcd! That works great, I adjusted it to use RGB colours which requires the addition of:

maxColorValue = 255

Just in case anyone else runs into the same problem.

I’ll keep an eye on the bug with pre-defined colours.