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

Custom colorscales #19

Open
pbugnion opened this issue Jun 19, 2016 · 2 comments
Open

Custom colorscales #19

pbugnion opened this issue Jun 19, 2016 · 2 comments
Labels

Comments

@pbugnion
Copy link
Contributor

pbugnion commented Jun 19, 2016

Plotly supports sending custom colorscales as well as the predefined ones. It might be nice to try and support that.

For instance, the following request body to the Plotly API seems to do what we expect (POST https://api.plot.ly/v2/plots ; you need to set the headers Plotly-Client-Platform to something (eg. scala), Content-Type to application/json and use basic auth with your username and password):

{
   "figure":{
      "data":[
         {
            "zsrc":"pbugnion:452:0049bf,2b5279,47daf1,964c04,6841d3,961eab",
            "type":"heatmap",
            "colorscale":[
               [
                  7,
                  "rgb(165,0,38)"
               ],
               [
                  7.1111111111111111,
                  "rgb(215,48,39)"
               ],
               [
                  7.2222222222222222,
                  "rgb(244,109,67)"
               ],
               [
                  7.3333333333333333,
                  "rgb(253,174,97)"
               ],
               [
                  8.4444444444444444,
                  "rgb(254,224,144)"
               ],
               [
                  8.5555555555555556,
                  "rgb(224,243,248)"
               ],
               [
                  8.6666666666666666,
                  "rgb(171,217,233)"
               ],
               [
                  8.7777777777777778,
                  "rgb(116,173,209)"
               ],
               [
                  8.8888888888888888,
                  "rgb(69,117,180)"
               ],
               [
                  9,
                  "rgb(49,54,149)"
               ]
            ]
         }
      ]},
   "world_readable":true
}

The colorscale field seems to be an array of 2-arrays containing a z-value and a color.

I think the following interface would work:

// current interface in, eg. contour plots
val p = ThreeDPlot().withSurface(zs, SurfaceOptions().colorscale("Viridis"))

// extensions
val customColorscale = Coloscale.fromIterable(
 List(7 -> Color.rgb(255, 0, 0), 7.5 -> Color.rgb(128, 128, 0), 8.0 -> Color.rgb(0, 255, 0))
)
val p = ThreeDPlot().withSurface(zs, SurfaceOptions().colorscale(customColorscale))

val customColorscale = Coloscale.fromFunction { z => 
  if (z < 10.0) { Color.rgb(255, 0, 0) } else { Color.rgb(0, 255, 0) }
}
val p = ThreeDPlot().withSurface(zs, SurfaceOptions().colorscale(customColorscale))
@pbugnion
Copy link
Contributor Author

@srstevenson Mostly raising this so we are aware of it. At the moment, I think it's fine to just stick to a string value for the colorscale, since the more complete implementation doesn't alter the interface.

@pbugnion
Copy link
Contributor Author

This describes setting custom colorscales in Python: https://plot.ly/python/heatmap-and-contour-colorscales/

@srstevenson srstevenson added the good first issue Good for newcomers label Sep 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

2 participants