Label outside of the box in a figure

82 vues (au cours des 30 derniers jours)
Darrell Gaydosh
Darrell Gaydosh le 16 Avr 2018
Commenté : Camille CAISSO le 16 Fév 2021
Using MATLAB R2017b. Starting with a figure containing an x-y plot, I added a second set of axes using...
ax1=gca;
ax1_pos = ax1.Position; % position of first axes
ax2 = axes('Position',ax1_pos,...
'XAxisLocation','top',...
'Color','none');
I changed the second x-axis limits, then added a label..
xlim([0.1 1.1]);
xlabel('Outer diameter, in');
The xlabel command added the label outside of the box in the figure.
I attempted to change both the 'OuterPosition' and 'InnerPosition' properties of the figure, independently, which resized the figure as expected, but the upper x-axis label still was out of the figure box regardless.
If I expand the figure window to full screen, the upper x-axis label is still not completely inside the box.
Can anyone explain how to fix this?
Thank you.
  2 commentaires
Paul Bonnefis
Paul Bonnefis le 9 Jan 2020
Modifié(e) : Paul Bonnefis le 9 Jan 2020
Hi,
I had the same problem and I found a solution. You can change the plot area inside the figure :
ax1=gca
ax1_old_pos=ax1.Position; % [ax ay bx by] 2 diagonal points defining the graph area
Yscale=0.9;
ax1.Position=[ax1_old_pos(1) ax1_old_pos(2) ax1_old_pos(3) ax1_old_pos(4)*Yscale];
Cheers,
Paul
Camille CAISSO
Camille CAISSO le 16 Fév 2021
Hi,
While making figures for my PhD Thesis I have done 2 differents codes for exactly the same kind of figures than you (with latex interpreter). The first one work's well, everything was fine. With the second one I have the same problem than you. So i decided to copare them and i found the command to solve it.
After all your subplots you just have to had the following command line :
set(gca,'TickLabelInterpreter','latex');
Yes, the problem comes from ticks size...
Currently working on Matlab R2020a.
Cheers,
Camille

Connectez-vous pour commenter.

Réponses (1)

Bhavanithya Thiraviaraja
Bhavanithya Thiraviaraja le 17 Avr 2018

You can use the property Editor to change/manage the position and font size of the axes. Click Edit, then Axes Properties. In the window which appears, you can click on the upper x axis Label and drag it down, or even reduce it's font size so it stays within the window.

After all the editings are done, if you want a MATLAB code for it, click File from the menu and then Generate code.

The code I tried generating is like below,

function createfigure1
%CREATEFIGURE1
%  Auto-generated by MATLAB on 17-Apr-2018 12:32:53
% Create figure
figure1 = figure;
% Create axes
axes('Parent',figure1);
% Create xlabel
xlabel('Outer diameter, mm');
% Create axes
axes1 = axes('Parent',figure1);
% Create xlabel
xlabel('Outer diameter, in');
% Create ylabel
ylabel('Transformation Shear Strain (%)');
% Set the remaining axes properties
set(axes1,'Color','none','XAxisLocation','top');

Hope this helps!

  1 commentaire
Darrell Gaydosh
Darrell Gaydosh le 17 Avr 2018
Thank you for the effort, but this does not help me. If I grab the x-axis label at the top and move it down, the plot box does not move, and the x-axis label just ends up superimposed on the plot. Also, I do need to maintain the font size.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Interactive Control and Callbacks dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by