www.gusucode.com > symbolic 源码程序 matlab案例代码 > symbolic/SetAxisLabelsAndTicksInTermsOfPiExample.m
%% Add Title and Axis Labels and Format Ticks % For $t$ values in the range $-2\pi$ to $2\pi$, plot the parametric line % % $$\matrix{x = t \cr y = t/2 \cr z = \sin(6t).}$$ % % Add a title and axis labels. Create the x-axis ticks by spanning the x-axis limits at intervals of % |pi/2|. Display these ticks by using the % |XTick| property. Create x-axis labels by using % |arrayfun| to apply |texlabel| to |S|. Display these labels % by using the |XTickLabel| property. Repeat these steps for the y-axis. % % To use LaTeX in plots, see <docid:symbolic_ug.f2-234358>. syms t xt = t; yt = t/2; zt = sin(6*t); fplot3(xt,yt,zt,[-2*pi 2*pi],'MeshDensity',30) view(52.5,30) xlabel('x') ylabel('y') title('x=t, y=t/2, z=sin(6t) for -2\pi < t < 2\pi') ax = gca; S = sym(ax.XLim(1):pi/2:ax.XLim(2)); ax.XTick = double(S); ax.XTickLabel = arrayfun(@texlabel, S, 'UniformOutput', false); S = sym(ax.YLim(1):pi/2:ax.YLim(2)); ax.YTick = double(S); ax.YTickLabel = arrayfun(@texlabel, S, 'UniformOutput', false);