when using heatmaps (and likewise contour plots) plotly.js leaves me no choices but to specifiy both: ‘raw’ data for the z attribute, and a colorscale to convert this raw data to a color.
I would like to specify the color for each grid point explizitely, instead of letting plotly derive it for me. Is there any way to achieve this?
I think it would make sense to have such an option. It would leave the choice of how color is derived from data to the user, instead of restricting him in an unnecessary way (at least I don’t see why it would hurt to let him specify color himself…).
Background: The problem is that plotly color scales only allow very simple mappings of data to color… In my use case I need to mix k values into one color. In a sense my z-data is k-dimensional and but plotly color scale only handles 1-d z data…
abstractly speaking I would just like the option of a custom mapper that converts my arbitrary z data to a color, say:
function my_mapper (z_data_item) {
// z_data_item can be anything. A scalar, a list, some class instance, …
// here I can do whatever I like with data_item …
my_color = super_complicated_calculation(data_item)
// but it returns a valid color, which will represent z_data_item in the resulting heatmap
return my_color
}
I think that would just give more power to the user in a neat, capsuled way. The default could still be to just use the normal color scale. But using an mapper function like above could be another option.
Anyway, you ask about my specific use case:
As said in my case each value of z is actually a sequence of k values. Each of these k values is in between 0 and 1. For each k there is a hue. Now I want the color for a particular value of z to be the weighted mixtures of these hues. It’s not exactly what I want to do, but I hope I made my point?
I see your point. Unfortunately, we’ll never allow passing custom functions through the official plotly.js API. Our data/layout attributes have to remain JSON-serializable by design.
Ok, I now see understand why you cannot have custom functions… Too bad!
As for the interface of heatmap: Why not add a paramter ‘color’, which provides a precomputed color for every data point to draw in the heatmap? That surely would be serializable.