在Matlab图中调整plotrange

时间:2015-04-14 02:57:03

标签: matlab plot matlab-figure

我正在寻找相当于Mathematica的PlotRange - > Matlab图中的{0,Pi}。如果我绘制一个函数,例如:

t = linspace(0, pi, 100) ;
plot( t, cos(t) )

我得到一个超过[0,3.5]区间的图,而不是[0,pi],如下图所示:

cos plot sample

1 个答案:

答案 0 :(得分:2)

t = linspace(0, pi, 100) ;
plot( t, cos(t) )
%% Change Xaxis Limits
xlim([0 pi])
%% Set current plot axis (gca) Xtick and XtickLabel to manually input data
set(gca, 'XTick',[0,0.25*pi,.5*pi,0.75*pi,pi]);
set(gca,'XTickLabel',{'0','\pi/4','\pi/2','3 \pi/4','\pi'});

%% See matlab 2015 version help

MATLAB 2015 Documentation