With Plotly.JS I have:
z0
a 500 x 200 array, to be displayed as'heatmap'
, with axis in millimeters in range 0 .. 2500mm x 0 .. 1000mm (thus the x, y axis are rescaled with a factormultiplier = 5.0
), here this trace is rendered as a constant grey color because the value is constantz1
an RGB array of size 2000 x 800 (x3 for RGB), to be displayed withtype: 'image'
, exactly on top ofz0
: both layers should be on top of each other (here it can work because same aspect ratio)
The following code works, but unfortunately, z1
doesn't take the full width / full height.
How to modify the following code such that the RGB image z1
takes the full width / full height, i.e. up to 2500mm and 1000mm for x, y axis ?
var multiplier = 5.0;
var z0 = Array.from({length: 200}, () => Array.from({length: 500}, () => 100));
var z1 = Array.from({length: 800}, () => Array.from({length: 2000}, () => [Math.random() * 255, Math.random() * 255, Math.random() * 255]));
var x_values = z0[0].map((el, idx) => idx * multiplier);
var y_values = z0.map((el, idx) => (z0.length - idx - 1) * multiplier);
const data = [
{type: 'image', z: z1, colormodel: 'rgb', x: x_values, y: y_values},
{type: 'heatmap', z: z0, colorscale: 'Cividis', opacity: 0.6, x: x_values, y: y_values }
];
const layout = {width: 600, xaxis: {anchor: 'y', scaleanchor: 'y', constrain: 'domain', "ticksuffix": " mm"}, yaxis: {anchor: 'x', autorange: 'reversed', constrain: 'domain', "ticksuffix": " mm"}};
Plotly.newPlot('plot', data, layout);
<script src="https://cdn.plot.ly/plotly-2.16.2.min.js"></script>
<div id="plot"></div>
Linked questions:
Note:
I tried to create other x: x_values_2, y: y_values_2
arrays for the trace z1
, with another multiplier, but it seems it has no effect.