Building colourmap from continuous x, y position data
51 ビュー (過去 30 日間)
古いコメントを表示
I want to create some sort of a heatmap using x,y position data. I want the axes of the figure to be x and y and the colour of the plotting to be more intense if there is more data around that position.
How can i achieve this?
0 件のコメント
採用された回答
Jack
2023 年 3 月 27 日
Hi,
To create a heatmap using x and y position data in MATLAB, you can use the histcounts2 function to create a 2D histogram of the data, and then visualize the results using the imagesc function. Here's an example:
% Generate some example data
x = randn(1000,1); % x position data
y = randn(1000,1); % y position data
% Create a 2D histogram of the data
nbins = 50; % number of bins in each dimension
[counts, edges] = histcounts2(x, y, nbins);
% Visualize the results as a heatmap
figure
imagesc(edges(1), edges(2), counts)
colormap(jet) % choose a colormap
colorbar % add a colorbar to the plot
axis xy % set the axis orientation to x-y
xlabel('x') % label the x-axis
ylabel('y') % label the y-axis
In this example, we first generate some random x and y position data. Then we use histcounts2 to create a 2D histogram with a specified number of bins (nbins). We then use imagesc to visualize the results as a heatmap, using the edges of the bins as the axes. Finally, we set the colormap, add a colorbar, and label the axes.
The resulting plot will have a more intense color in regions where there is more data. You can adjust the number of bins (nbins) to control the level of detail in the heatmap.
1 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Data Distribution Plots についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!