Filter löschen
Filter löschen

How to increase decimal places in corrplot function?

7 Ansichten (letzte 30 Tage)
Roja Eliza
Roja Eliza am 26 Sep. 2023
Kommentiert: Dyuman Joshi am 29 Sep. 2023
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.

Antworten (1)

Dyuman Joshi
Dyuman Joshi am 26 Sep. 2023
Bearbeitet: Dyuman Joshi am 26 Sep. 2023
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 Kommentare
Roja Eliza
Roja Eliza am 26 Sep. 2023
Thanks for the help. I actually changed all the values manually on the figure itself but I ll try this too.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Tags

Produkte


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by