필터 지우기
필터 지우기

Kombinieren von diskreten und kontinuierlichen Werten in einer heatmap

조회 수: 4 (최근 30일)
Tim Ehmes
Tim Ehmes 2023년 12월 11일
편집: Adam Danz 2023년 12월 20일
Ich möchte eine Matrix mit Werten in einer Heatmap darstellen. In der Matrix befinden sich diskrete Werte, zum Beispiel 100, 700, 900, die für z, x, p usw. stehen. Die Matrix enthält zusätzlich Werte, die auf einer kontinuierlichen Skala (abc [mm]) dargestellt werden, wie zum Beispiel Werte von 20 bis 80 [mm]. Ich habe das Problem bereits in R gelöst. Leider konnte ich keinen Ansatz dazu finden, wie ich die gleiche Heatmap wie im Anhang in Matlab umsetzen könnte.
Ich hoffe, ihr könnt mir helfen.

답변 (1개)

Adam Danz
Adam Danz 2023년 12월 13일
편집: Adam Danz 2023년 12월 20일
I don't see any continuous color gradients in the pdf attached to the question (screenshot below). There's a colorbar showing a continuous gradient but nowhere in the image is there a continuous gradient.
You could use imagesc or heatmap with the same matrix input to generate a similar image. The problems are
  1. generating the input matrix
  2. generating the colormap
Applying a smooth gradient would require significantly extra work or a completely different approach. The example below includes a section that has a continous change of colors but it's not a smooth gradient.
% Create the input matrix
z = zeros(10); % 0 = Color 1
z(1:8,3) = 1; % 1 = Color 2
z(5:10,5:6) = 2; % 2 = Color 3
z(8,4:5) = 3; % 3 = Color 4
% Continuous transition of colors
z(1:7,8:10) = (0:6)'+(1:3) + 3; % 4 to 12 for Colors 5-13
% Create the colormap
discreteColormap = [0 0 1; ... % Color 1
.5 1 0; ... % Color 2
.3 .3 .3; ... % Color 3
0 1 1, ... % Color 4
];
ContinuousColormap = hot(9); % for Colors 5-13
cmap = [discreteColormap; ContinuousColormap];
% Plot matrix as an image
imagesc(z)
colormap(cmap)
colorbar
You could break the colorbar up into 2 colorbars if you'd like - solutions are in this forum.
% Plot matrix using heatmap
figure()
heatmap(z)
colormap(cmap)

제품


릴리스

R2023a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!