Replace X and Y labels

조회 수: 3 (최근 30일)
Isa Duran
Isa Duran 2014년 4월 7일
편집: dpb 2014년 4월 7일
Hi guys
I'm dealing with a simple issue, how can I replace y label so it will be at the top of the y-axis, and x-label will be at the end of the x-axis?
The code:
* *
* * h=figure('Visible','on');
* *
* * for i=1:length(PD)/10:length(PD)
* * plot(J,Kt6(i,:))
* * hold on
* * plot(J,10*Kq10(i,:),'r--')
* * %plot(J,Ktk,'k')
* * plot(J,No(i,:))
* * grid on
* * axis([0 1.6 0 1])
* * xlabel('J')
* * ylabel({'K_t';'10K_Q';'\eta'},'rot',0)
%fname = 'C:\\fig';
%saveas(h, fullfile(fname, 'PropellerUktk'), 'jpeg');
%saveas(h, fullfile(fname, 'PropellerUktk'), 'fig');
Thanks
Isa

채택된 답변

dpb
dpb 2014년 4월 7일
편집: dpb 2014년 4월 7일
Save the handle of the label when you write it and then adjust the position and probably the horizontalalignment properties...
axis([0 1.6 0 1])
hXL=xlabel('J');
pXL=get(hXL,'position'); pXL(1)=1.6; % adjust to right axis limit
set(hXL,'position',pXL,'horizontalalign','right')
hYL=ylabel({'K_t';'10K_Q';'\eta'},'rot',0);
pYL=get(hYL,'position'); pXL(2)=1; % adjust to top axis limit
set(hYL,'position',pYL,'horizontalalign','right')
As always, "Salt to suit"...
  댓글 수: 1
Isa Duran
Isa Duran 2014년 4월 7일
Nice !! Thanks a lot :)
Isa

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

추가 답변 (1개)

David Sanchez
David Sanchez 2014년 4월 7일
Taka a look at the following code and adapted to your needs:
x = -pi:.1:pi;
y = sin(x);
h = plot(x,y)
set(gca,'XTick',-pi:pi/2:pi)
set(gca,'XTickLabel',{'-pi','-pi/2','0','pi/2','pi'})
title('Sine Function');
xlabel('Radians','FontSize',12,...
'FontWeight','bold','Color','r','Rotation',0,...
'Units','Pixels','Position',[600 0]);
ylabel('Function Value','FontSize',12,...
'FontWeight','bold','Color','r','Rotation',0,...
'Units','Pixels','Position',[0 400])

카테고리

Help CenterFile Exchange에서 Axis Labels에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by