MATLAB Answers

In figure object, how to change multiple subplot axis labels at once from gplotmatrix output?

12 views (last 30 days)
CCNASA on 25 Nov 2019
Answered: Surya Talluri on 5 Aug 2020
How do I change axis label properties from gplotmatrix output? Say I want to rotate the labels and change horizontal alignment for all at once. Right now, they overlap since the text boxes are oriented vertically. When they rotate to zero degrees, they overlap the tick labels.
I want to do this programmatically, not in the GUI, since I can have 15 rows and columns and it slows down once I start trying to manipulate it by hand. I've tried combinations of findobj, set, gcf, etc from many, many google results, but no luck. I can't find the internal id's for the various labels, either.
I can make it a loop as a function of column/row numbers if that's easier, but I haven't gotten a loop to do what I want yet for each subplot, just the figure as if it's a plot itself.

Answers (1)

Surya Talluri
Surya Talluri on 5 Aug 2020
I understand from your question that you want to rotate and adjust the position of the labels programmatically.
You can change rotation of labels by changing the “Rotation property of xlabel and ylabel. You can even change positions of labels by changing their Position property.
[h, ax, bigax] = gplotmatrix(X,Y,group);
for i = 1:15
ylabel( ax(i,1), ynames(i),'Rotation',0,'HorizontalAlignment','right')
xlabel( ax(15,i), xnames(i),'Rotation',90,'HorizontalAlignment','right')
ax(5, i).XLabel.Position(2) = ax(5, i).Position(2) - 0.1;
ax(I, 1).YLabel.Position(1) = ax(i, 1).Position(1) - 0.1;
Note: if you move the labels too far, it may no longer be visible.
You can refer to the gplotmatrix documentation for more information -

Community Treasure Hunt

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

Start Hunting!

Translated by