2014-12-11 3 views
4

내 마지막 마무리 연습을 위해이 그래프를 복사하려고하지만 글꼴, 크기 또는 축 레이블을 변경하는 방법을 이해하지 못합니다. 간단히 말해,이 코드를 내 코드에서 정확히 복제해야합니다. 나는 마커 크기가 8 인 새로운 로마자와 크기 18의 폰트가 필요하다. 어떻게이 코드를 포맷 할 수 있을까?다른 그림, 글꼴, 크기 레이블 MATLAB

clear 
clc 

x = linspace(0,2); 
y1 = sin(2*pi*x); 
y2 = exp(-0.5*2*pi*x).*sin(2*pi*x); 


figure 
subplot(2,1,1); 
hPlot1 = plot(x,y1,'rs'); 
ylabel('f(t)') 
set(gca,'YLim',[-1 2],'YTick',-1:1:2,'XTick',0:.5:2) 

subplot(2,1,2); 
hPlot2 = plot(x,y2,'k*'); 
xlabel('Time(s)') 
ylabel('g(t)') 
set(gca,'YLim',[-0.2,0.6],'YTick',[-0.2,0,0.2,0.4,0.6],'XTick',0:.5:2) 

답변

3

에 의해 xlabel('Time(s)') 교체 :

xlabel('Time(s)','FontName','TimesNewRoman','FontSize',18) 

ylabel에 대해 동일한 작업을 수행 enter image description here

이 내 코드입니다. 마커의 크기

,

hPlot1 = plot(x,y1,'r-',x(1:5:end),y1(1:5:end),'ks','MarkerSize',8); 

다른 플롯 동일한 hPlot1 = plot(x,y1,'rs'); 의해 대체.

마지막으로, 당신은 당신이 xlabelylabel와 마찬가지로, 글꼴 크기 및 글꼴 이름을 변경할 수 있습니다,

text(0.5,1.5,'Harmonic force f(t) = sin(\omega t)') 

다시 text 기능을 사용하여 그림, 예컨대 : 텍스트를 추가 할 수 있습니다. 아래

+0

안녕하세요. 감사합니다. 그래프와 모든 것이 맞지만 어떤 이유로 텍스트가 MATLAB R2014a에 표시되지 않지만 Linux 및 matlab 2013이 실행되는 랩 컴퓨터를 사용할 때 나타나지 않습니다. Ps Windows 8을 실행 중이고 명령에서 "unable 라텍스 해석 " –

+0

해석자를 'latex'로 지정해야 할 것입니다 : text (0.5,1.5, '고조파 힘 f (t) = sin (\ omega t)', 'interpreter', 'latex') ' – am304

4

코드 :

%// x = linspace(0,2); %// changed that to respect where the markers are on your example figure 
x = 0:0.1:2 ; 
y1 = sin(2*pi*x); 
y2 = exp(-0.5*2*pi*x).*sin(2*pi*x); 

figure 
h.axtop = subplot(2,1,1) ; 
h.plottop = plot(x,y1,'LineStyle','-','Color','r', ... 
        'Marker','s', ... 
        'MarkerEdgeColor','k', ... 
        'MarkerFaceColor','none', ... 
        'MarkerSize',8) ; 
set(gca,'YLim',[-1 2],'YTick',-1:1:2,'XTick',0:.5:2) 
h.ylbl(1) = ylabel('\itf(t)') ;  %// label is set in "italic" mode with the '\it' tag at the beginning 

h.axbot = subplot(2,1,2); 
h.plotbot = plot(x,y2,'-ks', ... 
        'Marker','*', ... 
        'MarkerEdgeColor','r', ... 
        'MarkerSize',8) ; 
set(gca,'YLim',[-0.2,0.6],'YTick',[-0.2,0,0.2,0.4,0.6],'XTick',0:.5:2) 
h.xlbl(1) = xlabel('Time(s)') ; 
h.ylbl(2) = ylabel('\itg(t)') ;  %// label is set in "italic" mode with the '\it' tag at the beginning 

%// create the "text" annotations 
h.txttop = text(0.5,1.5, 'Harmonic force \itf(t)=sin(\omegat)' , 'Parent',h.axtop) ;     %// note the 'parent' property set to the TOP axes 
h.txtbot = text(0.5,0.3, 'Forced response \itg(t)=e^{\zeta\omegat} sin(\omegat)' , 'Parent',h.axbot) ; %// note the 'parent' property set to the BOTTOM axes 

%// set the common properties for all text objects in one go 
set([h.xlbl h.ylbl h.txttop h.txtbot] , 'FontName','Times New Roman' , 'FontSize',18) 

다음 그림을 생성합니다 : 그래픽 객체의 핸들이 저장된 이후에 속성을 설정하는-재사용 방법 figure

참고. 여러 그래픽 오브젝트 (다른 ​​경우에도)가 동일한 특성을 갖는 경우,이 특성을 모든 그래픽 오브젝트에 한 번에 지정할 수 있습니다.

그림에 주석을 추가하는 방법에 대한 자세한 내용은 Matlab text 함수 설명서를 참조하십시오.

+0

그게 뭐래? +1 – kkuilla