Filter löschen
Filter löschen

Add label to sub-axes in plotmatrix

52 Ansichten (letzte 30 Tage)
Isabel Chen
Isabel Chen am 15 Mär. 2015
Kommentiert: Austin M. Weber am 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!!

Akzeptierte Antwort

Isabel Chen
Isabel Chen am 20 Mär. 2015
Just in case anyone is interested,
ylabel(AX(1,1),'str1')
ylabel(AX(2,1),'str2')
xlabel(AX(8,1),'str3')
xlabel(AX(8,2),'str4')
does the trick.
  2 Kommentare
Brendan
Brendan am 22 Sep. 2017
Bearbeitet: Brendan am 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
Austin M. Weber am 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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Brendan
Brendan am 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 Kommentar
Nasrin
Nasrin am 2 Mär. 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..

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Labels and Annotations finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by