Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
118 views
in Technique[技术] by (71.8m points)

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

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.

question from:https://stackoverflow.com/questions/66046839/how-to-pass-array-of-array-to-plotly-instead-of-defining-it-within-the-chart-lay

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...