The label of the top x axis appears outside of the figure, how can this be fixed?
Also, for some reason I don't understand, "hold on + plot()" doesn't work in this case, I would like to be able to plot a vertical line but this doesn't appear on the figure either
figure1=figure(4)
axes1 = axes('Parent',figure1,'YScale','log','XScale','log','Layer','top');
grid(axes1,'on');
hold(axes1,'on');
[C,h]=contourf(peaks,[10],'LineColor','none');
clabel(C,h);
hold on %doesn't work
plot([10 10],[0 10],'--k','LineWidth',2) %doesn't work
axis tight;
axis([1 50 1 50])
xlabel('\lambda_x','Fontsize',20);
ylab=ylabel('y^+','Fontsize',20);
grid off
set(ylab, 'Units', 'Normalized', 'Position', [-0.1, 0.5, 0]);
set(gca,'linewidth',1.5,'FontSize',16)
colormap(flipud(gray(256)));
colorbar;
ax2 = axes('Position',axes1.Position,'YScale','log','XScale','log','XAxisLocation','top','YAxisLocation','right','Color','none','YTick',[]);
xla2=xlabel(ax2,'\lambda_x^+','Fontsize',20);
axis(ax2,[1*100 50*100 1*100 50*100])
set(ax2,'linewidth',1.5,'FontSize',16)
% Top x axis' label appears outside of figure

댓글 수: 2

Mischa Kim
Mischa Kim 2020년 12월 27일
Carlos, how do you want the figure to look like? Is this for an app or a standalone figure?
carlos g
carlos g 2020년 12월 27일
Hi Mischa Kim, the figure is for a latex document, I guess the first problem can be solved by enlarging the figure by using a command (which I don't know) or making space on the top for the label. I have no idea about the second problem, though (hold on doesn't seem to work).

댓글을 달려면 로그인하십시오.

답변 (2개)

Image Analyst
Image Analyst 2020년 12월 27일

0 개 추천

I've seen that before too, like when my title font size is too big. You can reduce the axes size to get it to fit by setting the 'InnerPosition', 'OuterPosition', or 'Position' property.
ax = gca
ax.units = 'normalized';
ax.Position = [0.1, 0.1, 0.7, 0.7]; % Adjust as needed to get the size and location correct.

댓글 수: 8

carlos g
carlos g 2020년 12월 27일
With that command I was able to change the position of the axis but not the plot's, leading to
but there is not enough space at the top to accomodate for the numbers and the label
Image Analyst
Image Analyst 2020년 12월 27일
Not sure what you did. Explore the other properties of ax that you can set.
carlos g
carlos g 2020년 12월 27일
how could the printed region (the white canvas) be enlarged? I lack space at the top part
Image Analyst
Image Analyst 2020년 12월 27일
Did you try setting the OuterPosition property? Otherwise, give me code to reproduce your log image/graph/plot or whatever it is.
carlos g
carlos g 2020년 12월 27일
The code is in the post, plus the lines that you added. Thank you!
Try this. You might still have to play around with the OuterPosition property:
figure1=figure;
axes1 = axes('Parent',figure1,'YScale','log','XScale','log','Layer','top');
grid(axes1,'on');
hold(axes1,'on');
[C,h]=contourf(peaks,[10],'LineColor','none');
clabel(C,h);
hold on %doesn't work
plot([10 10],[0 10],'--k','LineWidth',2) %doesn't work
axis tight;
axis([1 50 1 50])
xlabel('\lambda_x','Fontsize',20);
ylab=ylabel('y^+','Fontsize',20);
grid off
set(ylab, 'Units', 'Normalized', 'Position', [-0.1, 0.5, 0]);
set(gca,'linewidth',1.5,'FontSize',16)
colormap(flipud(gray(256)));
colorbar;
ax1 = gca;
ax2 = axes('Position',axes1.Position,'YScale','log','XScale','log','XAxisLocation','top','YAxisLocation','right','Color','none','YTick',[]);
xla2=xlabel(ax2,'\lambda_x^+','Fontsize',20);
axis(ax2,[1*100 50*100 1*100 50*100])
set(ax2,'linewidth',1.5,'FontSize',16)
gf = gcf;
gf.WindowState = 'Maximized'
% Top x axis' label appears outside of figure
% so adjust both to shrink them.
ax1.Units = 'normalized';
ax1.OuterPosition = [0, 0, .75, .75];
ax2.Units = 'normalized';
ax2.OuterPosition = [0, 0, .75, .75];
carlos g
carlos g 2020년 12월 28일
편집: carlos g 2020년 12월 28일
No, it doesn't work because with OuterPosition I am able to shrink the axis but i can't control its position (by playing with the numbers the axis gets shrinked more or less but the position then changes).
Also, do you know why
hold on %doesn't work
plot([10 10],[0 10],'--k','LineWidth',2) %doesn't work
doesn't work?
Image Analyst
Image Analyst 2020년 12월 28일
I don't really know. I'm not going to experiment around with it anymore. Can you call tech support? They're open now.

댓글을 달려면 로그인하십시오.

Siddhant Desai
Siddhant Desai 2022년 5월 19일

0 개 추천

I have faced a similar issue where the colorbar labels end up outside the plot area. I don't know how to automate the resizing so that everything fits and end up having to do it manually which is very cumbersome.

카테고리

도움말 센터File Exchange에서 Axis Labels에 대해 자세히 알아보기

질문:

2020년 12월 27일

답변:

2022년 5월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by