How to pass array of array to Plotly instead of defining it within the chart layout

Viewed 122

I am trying to create a Plotly JS colorscales graph using a Z index array of an array. When defining the Z index like so:

var data = [{
   z: [[-45970100.0, -45968489.0, -45966877.0, -45965266.0, ...]],
   colorscale: [
   ['0.0', 'rgb(165,0,38)'],
   ['0.111111111111', 'rgb(215,48,39)'],
   ['0.222222222222', 'rgb(244,109,67)'],
   ['0.333333333333', 'rgb(253,174,97)'],
   ['0.444444444444', 'rgb(254,224,144)'],
   ['0.555555555556', 'rgb(224,243,248)'],
   ['0.666666666667', 'rgb(171,217,233)'],
   ['0.777777777778', 'rgb(116,173,209)'],
   ['0.888888888889', 'rgb(69,117,180)'],
   ['1.0', 'rgb(49,54,149)']
   ],
   type: 'heatmap'
}];
Plotly.newPlot('myDiv', data);

the chart plots vertically as intended Vertical Colorscale, but when I pass the same array of array as a variable like so:

function chart(zX):
   var data = [{
      z: zX,
      colorscale: [
      ['0.0', 'rgb(165,0,38)'],
      ['0.111111111111', 'rgb(215,48,39)'],
      ['0.222222222222', 'rgb(244,109,67)'],
      ['0.333333333333', 'rgb(253,174,97)'],
      ['0.444444444444', 'rgb(254,224,144)'],
      ['0.555555555556', 'rgb(224,243,248)'],
      ['0.666666666667', 'rgb(171,217,233)'],
      ['0.777777777778', 'rgb(116,173,209)'],
      ['0.888888888889', 'rgb(69,117,180)'],
      ['1.0', 'rgb(49,54,149)']
      ],
      type: 'heatmap'
   }];
   Plotly.newPlot('myDiv', data);

the chart plots horizontal Horizontal Colorscale

How can I make it so that passing an array of an array as a variable to a function plots the chart vertically?

Note: I've left the x and y axis data as they are just labels and do not impact the Z index coordinates.

0 Answers
Related