Label outside of the box in a figure
44 次查看(过去 30 天)
显示 更早的评论
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/189514/image.png)
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 个评论
Paul Bonnefis
2020-1-9
编辑:Paul Bonnefis
2020-1-9
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
2021-2-16
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
回答(1 个)
Bhavanithya Thiraviaraja
2018-4-17
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');
![](/matlabcentral/answers/uploaded_files/113454/untitled.jpg)
Hope this helps!
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Axis Labels 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!