Autoarrange title and top xlabel on plot
Afficher commentaires plus anciens
Hello, I have a plot with an extra x-axes on the top (including ticks, numbers, label).
However, the position of this top xlabel is either outside of the plot window (in case of a small window size) or conflicts with title of the plot (bigger window).
Is there a way to "auto-arrange" the position of these text elements, so that independent from window size, title, top xlabel and x-numbers are always visible?
Below you find a simple code example and also a picture, where the "conflict" is even more noticeable.
plot(0,0)
xlabel('time [s]')
primary_axis = gca;
secondary_axis = axes('Position',primary_axis.Position,'XAxisLocation','top','YAxisLocation','right','Color','none'); % secondary_axis = new active axes (top + right)
xlabel('time [h]')
title('example')
Thank you very much, Dan

2 commentaires
Dan H
le 5 Oct 2018
Well, you have to add the title to the axes with an xaxis on top
Add these two lines in your function
title('Title');
primary_axis.Position=secondary_axis.Position
at the location right above this line
axes(primary_axis);
I have adjusted your script, please have a look. As a rule of thumb, output your axes handles if you create them in a loop. Makes it easier to adjust things at the end of the script.

Réponse acceptée
Plus de réponses (1)
KALYAN ACHARJYA
le 5 Oct 2018
Modifié(e) : KALYAN ACHARJYA
le 5 Oct 2018
try this one, maybe it helps, this answer is not automated set, but the title will display without overlapping
title({'First line';'';' '})

Catégories
En savoir plus sur Title dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!