Initial values on the plot

조회 수: 4 (최근 30일)
stelios loizidis
stelios loizidis 2022년 1월 12일
답변: Voss 2022년 3월 30일
Hello. I have a matrix X (2X40). In the values of this matrix I apply normalization and matrix Xnorm appear (2X40). Next, I make the contour plot of matrix Xnorm. What I want is for the contour plot to show as a label and the initial values, that is the value found in matrix X. How is this done?
Your help is valuable !!!
  댓글 수: 3
stelios loizidis
stelios loizidis 2022년 1월 12일
For example: X (1,1) =-22.5, X (1,2) =-1.5, X (1,3) =2.00, X(1,4)=-0.05
The contour plot I have concerns matrix Xnorm. What I want is if it is done on the contour plot, to have the initial value before normalization. For example, the first point of the contour plot corresponds to the value X (1,3)=2.00, the second point of the contour plot corresponds to the value X (1,4)=-0.05 and so on. What I want is for the contour plot to show like a label the corresponding value from matrix X.
Biral Pradhan
Biral Pradhan 2022년 3월 30일
I understand, you want modify the default labels in the contour plot to show values corresponding to your original matrix. Currently we are not supporting this feature. I have brought this issue to the notice of the concerned people and it might be considered for a future release.

댓글을 달려면 로그인하십시오.

답변 (1개)

Voss
Voss 2022년 3월 30일
Here's an approach that may work for you (an approach taken from this recent answer):
% make up some X:
X = [-22.5 -1.5 2.00 -0.05; -20.5 -0.5 1.00 -4.05];
% calculate X_norm from X:
X_min = min(X(:));
X_max = max(X(:));
X_norm = (X-X_min)/(X_max-X_min);
% create the contour:
[~,h] = contour(X_norm,'ShowText','on');
% make a colorbar to illustrate that the contour values use X_norm (0 to 1):
colorbar();
drawnow() % required
% get the levels used in the contour:
levels_norm = get(h,'LevelList');
% get the corresponding "unnormalized" levels
levels = levels_norm*(X_max-X_min)+X_min;
% get the index of each text's String in the (normalized) levels:
[~,idx] = min(abs(levels_norm-str2double(get(h.TextPrims,'String'))),[],2);
% set each text's String to the corresponding unnormalized level:
for ii = 1:numel(idx)
set(h.TextPrims(ii),'String',num2str(levels(idx(ii))));
end

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by