Xlabel in figure is only at center position when the figure is big
6 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Michael Werthmann
il 12 Lug 2021
Commentato: Michael Werthmann
il 13 Lug 2021
Hello,
I have a problem with visualising data. I want to move the xlabel of a plot inside the axis. I use this code for it:
figure
[jac_c, jac_m, jac_h, jac_gnames] = multcompare(jac_stats, 'CType','dunn-sidak');
title('');
xlh = xlabel('Ranks');
set(gca, 'FontSize', fsz, 'LineWidth', alw, 'fontname',ft);
set(findobj(gca,'type','line'),'linew', lw);
xlh.Position(2) = xlh.Position(2) + 0.5;
print('jac_anova','-dpng','-r300');
For some cases this works well:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/682508/image.png)
However, for other it does not, since the xlabel is not centered anymore:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/682513/image.png)
For this case, the xlabel is only centered when I expand the figure:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/682518/image.png)
What is going wrong here?
Thanks and kind regards
Michael
0 Commenti
Risposta accettata
Chunru
il 13 Lug 2021
When you set the xlim and ylim as auto by default, they will change automatically when the axes is resized. So the position of the label may be changed. To ensure the label is at the centre, set tha axis limit manually before issuing xlabel command:
plot(randn(10,1), randn(10,1), 'ro');
xlim([-3 3]);
hx = xlabel('Ranks');
hx.Position(2) = hx.Position(2) + 1;
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Specifying Target for Graphics Output in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!