Effacer les filtres
Effacer les filtres

Add label to sub-axes in plotmatrix

54 vues (au cours des 30 derniers jours)
Isabel Chen
Isabel Chen le 15 Mar 2015
Commenté : Austin M. Weber le 15 Fév 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!!

Réponse acceptée

Isabel Chen
Isabel Chen le 20 Mar 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 commentaires
Brendan
Brendan le 22 Sep 2017
Modifié(e) : Brendan le 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 le 15 Fév 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

Connectez-vous pour commenter.

Plus de réponses (1)

Brendan
Brendan le 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 commentaire
Nasrin
Nasrin le 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..

Connectez-vous pour commenter.

Catégories

En savoir plus sur Labels and Annotations dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by