How to increase decimal places in corrplot function?

조회 수: 7 (최근 30일)
Roja Eliza
Roja Eliza 2023년 9월 26일
댓글: Dyuman Joshi 2023년 9월 29일
I have this code data = [ x y z]; % here original dataswere added
% Calculate the correlation matrix
corrMatrix = corr(data)
% Create a correlation plot
corrplot(corrMatrix,'type', 'Pearson','testR', 'on', 'varNames', {'TO', 'AN', 'TC%', 'TN%', 'C/N', 'F', 'M', 'Temp°C'});
and I got this graph but i want to increase the decimal places of the r2 values in the graph as it is showing the rounded off values. How can i change the code to do so.

답변 (1개)

Dyuman Joshi
Dyuman Joshi 2023년 9월 26일
편집: Dyuman Joshi 2023년 9월 26일
I don't have your data, so I am working with the 1st example from the documentation of corrplot.
load Data_Canada
[R,~,H] = corrplot(Data)
R = 5×5
1.0000 0.9266 0.7401 0.7287 0.7136 0.9266 1.0000 0.5908 0.5716 0.5556 0.7401 0.5908 1.0000 0.9758 0.9384 0.7287 0.5716 0.9758 1.0000 0.9861 0.7136 0.5556 0.9384 0.9861 1.0000
H =
5×5 graphics array: Histogram Line Line Line Line Line Histogram Line Line Line Line Line Histogram Line Line Line Line Line Histogram Line Line Line Line Line Histogram
Here, H is the handle to the plotted graphics objects.
s = size(H);
%Indices of the elements of H to be modified
idx = find(~eye(s));
%Get the parent object of H
ax = get(H,'parent');
%Get the children of parent of H
ch = reshape(get([ax{:}],'Children'),s)
ch = 5×5 cell array
{1×1 Histogram} {3×1 Graphics } {3×1 Graphics } {3×1 Graphics } {3×1 Graphics } {3×1 Graphics } {1×1 Histogram} {3×1 Graphics } {3×1 Graphics } {3×1 Graphics } {3×1 Graphics } {3×1 Graphics } {1×1 Histogram} {3×1 Graphics } {3×1 Graphics } {3×1 Graphics } {3×1 Graphics } {3×1 Graphics } {1×1 Histogram} {3×1 Graphics } {3×1 Graphics } {3×1 Graphics } {3×1 Graphics } {3×1 Graphics } {1×1 Histogram}
%Let's check the corresponding graphics
ch{2}
ans =
3×1 graphics array: Text (corrCoefs) Line (lsLines) Line
ch{2}(1)
ans =
Text (corrCoefs) with properties: String: '0.93' FontSize: 10 FontWeight: 'bold' FontName: 'Helvetica' Color: [0.1294 0.1294 0.1294] HorizontalAlignment: 'left' Position: [0.1000 0.9000 0] Units: 'normalized' Use GET to show all properties
The 'String' property of the 'Text' objects are the one you want to change.
for k=1:numel(idx)
%Change the text values to numbers in text form with 4 digits after decimal
set(ch{idx(k)}(1),'String',sprintf('%0.4f',R(idx(k))));
%Changing the font size
set(ch{idx(k)}(1),'FontSize',8)
end
  댓글 수: 2
Roja Eliza
Roja Eliza 2023년 9월 26일
Thanks for the help. I actually changed all the values manually on the figure itself but I ll try this too.

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

카테고리

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

태그

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by