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

how to replace the color chunk in top heatmap #7000

Open
honghh2018 opened this issue May 17, 2024 · 0 comments
Open

how to replace the color chunk in top heatmap #7000

honghh2018 opened this issue May 17, 2024 · 0 comments

Comments

@honghh2018
Copy link

Thanks to develop the great tools,
I want to plot the heatmap with color bar top in heatmap like below,picture
image

but i get the below picture
image

even thought i relpace the element the trace in array, it color bar like below picture
image
It distance from the body heatmap

var z_data = [];
   for (var i = 0; i < 15; i++) { // 15行基因
       var temp_row = [];
       for (var j = 0; j < 100; j++) { // 每行100个细胞
           temp_row.push(Math.random());
       }
       z_data.push(temp_row);
   }
   var genes = Array.from({length: 15}, (_, i) => `Gene${i + 1}`);
   var cells = Array.from({length: 100}, (_, i) => `Cell${i + 1}`);

   // 分群信息,分组不均匀
   var groupAssignments = [20, 15, 25, 10, 30]; // 各组的细胞数
   var clusterColorBar = [];
   var groupColors = ['red', 'green', 'blue', 'yellow', 'purple']; // 分组颜色

   groupAssignments.forEach((count, index) => {
       clusterColorBar = clusterColorBar.concat(Array(count).fill(index + 1));
   });


   var trace = [

       {
           x: cells,
           y: ['Cluster'],
           z: [clusterColorBar.map(value => value)], // 使用实际数值
           type: 'heatmap',
           colorscale: groupColors.map((color, index) => [index / (groupColors.length), color]),
           showscale: false,
           hoverinfo: 'skip', // 禁用悬停信息
           domain: {
               x: [0.5, 1],
               y: [0, .5]
           },
       },
       {
           z: z_data,
           x: cells,
           y: genes,
           type: 'heatmap',
           colorscale: 'Viridis',
           // hoverinfo: 'all' // 默认显示所有信息
           domain: {
               x: [0.5, 1],
               y: [0, .5]
           }

       }

   ]



   // 绘制图表
   // Plotly.newPlot('heatmap', [clusterTrace,heatmapTrace], layout);
   // Plotly.newPlot('heatmap', [clusterTrace,heatmapTrace], layout);
   Plotly.newPlot('heatmap', trace);
   trace[1].domain.x=[0,1]
   trace[1].domain.y=[0,1]

any advice would be appreciated,
Best,
hanhuihong

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant