Add label to sub-axes in plotmatrix
48 views (last 30 days)
Show older comments
Isabel Chen
on 15 Mar 2015
Commented: Austin M. Weber
on 15 Feb 2024
I am using the plotmatrix function and would like to label the sub-axes (along the major Y axis and X axis only, of course). I've managed to turn all the YTickLabels and XTickLabels off:
set(AX,'YTickLabel',[]);
but cannot figure out how to change the current axes from BigAx to the required subaxes in AX. I can manually add the labels using plotTools, but there must be a way to do this using code? I have a large-ish matrix (10x10 minimum) so it would a real help to be able to write a script to do this. Please help!!
0 Comments
Accepted Answer
Isabel Chen
on 20 Mar 2015
2 Comments
Brendan
on 22 Sep 2017
Edited: Brendan
on 22 Sep 2017
The above suggestion doesn't work. This does.
X = randn(50,3);
Y = reshape(1:150,50,3);
[~,ax]=plotmatrix(X,Y);
ax(1,1).YLabel.String='Test1';
ax(2,1).YLabel.String='Test2';
ax(3,1).YLabel.String='Test3';
ax(3,1).XLabel.String='Test7';
ax(3,2).XLabel.String='Test8';
ax(3,3).XLabel.String='Test9';
Austin M. Weber
on 15 Feb 2024
To save time, I recommend labeling the sub-axes programatically using a for-loop:
% Let's say you have the following data table
variable_names = {'Dog','Cat','Bird','Fish','Goat','Man','Bear','Pig'};
rng(0)
data_table = array2table(10.*randn(60,8)+50,'VariableNames',variable_names);
% Use plotmatrix to visualize the data and add axis labels with a for-loop
[~,ax] = plotmatrix(data_table{:,:});
iterations = size(ax,1);
for i = 1:iterations
ax(i,1).YLabel.String = variable_names(i);
ax(iterations,i).XLabel.String = variable_names(i);
end
More Answers (1)
Brendan
on 22 Sep 2017
To create a sublabel on plotmatrix (on the outer subplots) use something like the following... The suggested answer above doesn't work.
X = randn(50,3);
Y = reshape(1:150,50,3);
[~,ax]=plotmatrix(X,Y);
ax(1,1).YLabel.String='Test1';
ax(2,1).YLabel.String='Test2';
ax(3,1).YLabel.String='Test3';
ax(3,1).XLabel.String='Test7';
ax(3,2).XLabel.String='Test8';
ax(3,3).XLabel.String='Test9';
1 Comment
Nasrin
on 2 Mar 2020
Thanks for sharing this code, I have a correlation plot with 14 variables.. I need to place all the lables.. but there is no enough space..
I've tested figure and label properties but they dont work..
How to modify this string type lables; for instance changing their orientation or font size..
See Also
Categories
Find more on Axis Labels 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!