Problem in making multiple scatterplots/subplots?
9 views (last 30 days)
Show older comments
Hi everyone,
I am suppose to make 9 scatterplots/subplots in one figure/plot (separate is fine too). My data comprises of 4 variables named as G_temp, Aerosols (Aerosols Concentration), Volume and B_temp. I want to check the relationship between these 4 using scatterplots. What I tried to do for single scatterplot till now is:
Data=readtable('F:\My_Table\Data.xlsx', 'Sheet', 1, 'ReadVariableNames', true, 'VariableNamingRule','preserve');
N = 0:50:500; %
Data.Volume_Bin=discretize(Data.Volume,N);
figure
hAx=axes; hold on;
hL=splitapply(@plotrows,Data.Aerosols,Data.G_Temp,Data.Volume);
hAx.XScale='log'; grid on;
set(gca, 'YDir', 'reverse');
% plotrows function
function hL=plotrows(x,y,varargin)
xy=sortrows([x y]);
hL=scatter(xy(:,1),xy(:,2),varargin{:},'filled');
end
In the above code I checked relationship between three variables G_Temp, Aerosols and Volume. Also I want to make 3 bins of Volume (0-500, 500-900, 900-inf) and then plot it versus G_temp and Aerosols concentration. The above code is just for 1st bin (0-500) of volume and produces following scatterplot:
If I try to include the fourth variable.
N2 = 0:1:10
Data.BTemp = discretize(Data.B_Temp, N2);
hL=splitapply(@plotrows,Data.Aerosols,Data.G_Temp,Data.Volume, Data.BTemp);
Following is the result. This is for the first bin of volume and first bin of B_Temp.
Actually this is something which I am trying to make:
For the first bin of Energy and B_Temp, check relationship between G_temp and Aerosol conc. Moving to the next column, for the second bin of energy and first bin of B_Temp check relationship between G_temp and Aerosol conc, and so on.
I would really appreciate if someone can tell me how to do this. Thank you.
Data is attached.
0 Comments
Answers (1)
Abderrahim. B
on 26 Aug 2022
Hi!
If my understanding is correct, there is a function called plotmatrix that comes with MATLAB and that I believe is more suitable for your case.
Below is a example on how to use ithe plotmatrix function.
dataTble = readtable('Data.xlsx', 'Sheet', 1, 'ReadVariableNames', true, 'VariableNamingRule','preserve');
varNames = string(dataTble.Properties.VariableNames);
% plotmatrix only accepts matrix as input argument
Data = table2array(dataTble) ;
[S,AX,BigAx,H,HAx] = plotmatrix(Data,Data ) ;
for ii = 1:4
AX(4,ii).XLabel.String = varNames(1,ii) ;
AX(ii,1).YLabel.String = varNames(1,ii) ;
S(ii,ii).Color = 'k' ; % this is just to highlight a variable when compared to itself.
end
Note that you still can improve the readability of this plot, for instance changing the color each each axes ..
Hope this helps
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!