轴外观,matlab

时间:2014-11-13 21:07:48

标签: matlab plot

我试图在图中绘制cos(x)和sin(x)。 这是我的代码:

 t = -pi:0.01:(pi);
 x = cos(t);
 y = sin(t);
plot(t,x,'b'); hold on;
plot(t,y,'r'); 

 axis([-pi pi -1 1])


 legend('cos(t)','sin(t)','Location','NorthWest')
 title('Plot of cos(x) and sin(x) between -2\pi and 2\pi')

我想更改y轴上的数字,以便我只有-pi,-pi / 2,0,pi pi 有什么帮助吗?

1 个答案:

答案 0 :(得分:1)

你可能想要:

set(gca,'XTick',-pi:pi/2:pi)
set(gca,'XTickLabels',{'-\pi','-\pi/2','0','\pi/2','\pi'})