Number of digits in heatmap plot except for the value 0
조회 수: 12 (최근 30일)
이전 댓글 표시
I have a 5X5 matrix and want to show the digits up to 3 decimals in the heatmap. However, I don't want to show the digits if the value in the matrix is 0 or almost 0 (like 10^-7). For example, I want to prevent 0 turns int 0.000. How to fix it?
I know you can use the beneath that changes ALL the elements in the matrix, but that is not what I'm looking for.
h.CellLabelFormat = '%.3f'
댓글 수: 0
답변 (1개)
Adam Danz
2023년 9월 6일
편집: Adam Danz
2023년 9월 7일
Replace near-0s with 0
>I want to show them as value ''0'' and not ''0.000'' and for the non-zero values in matrix I want three decimals.
You could replace the near-zeros with 0s where "near zero" is defined by some threashold as shown below. Then show up to 3 significant digits.
% Create data with near-zeros
data = rand(8)*10;
data(3:5:end) = rand(1,13)*10e-06;
% Replace near-zeros with 0
threshold = 10e-05;
data(abs(data) < threshold) = 0;
% plot results
figure()
h = heatmap(data);
h.CellLabelFormat = '%.3g';
Replace near-0s with NaNs
> I don't want to show the digits if the value in the matrix is 0 or almost 0 (like 10^-7)
You could replace the near-zeros with NaNs where "near zero" is defined by some threashold as shown below. Then show 3 decimal places.
% Replace near-zeros with NaN
threshold = 10e-05;
data(abs(data) < threshold) = NaN;
% plot results
figure()
h = heatmap(data);
h.CellLabelFormat = '%.3f';
댓글 수: 2
참고 항목
카테고리
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!