Matlab_Graphics(1)_2D

时间:2021-05-17 07:55:40

1.Add title ,axis Lables, and Legend to Graph:

 x=linspace(-*pi,2pi,);
y1=sin(x);
y2=cos(x);
figure
plot(x,y1,x,y2);
title('Graph of sine and cosine between -2\pi and 2\pi');% to display Greek symbols in a title,use the tex markup '\'
xlabel('-2\pi<x<2\pi'); % x-axis label
ylabel('sine and cosine value');% y-axis label
legend('y=sin(x)','y=cos(x)'); % add legend

2.change Graph axis Limits functions:

  Axis function: Axis([xmin,xmax,ymin,ymax]); or xlim([xmin,xmax])/ylim([ymin,ymax])/zlim([zmin,zmax])

3.Change Tick Marks and Tick Labels of Graph:

x=linspace(-,,);
y=cos(x);
figure
plot(x,y)
h=gca; % Use gca to get the handle for the current axes
h.XTick=[-*pi,-*pi,-pi,,pi,*pi,*pi];
h.YTick=[-,-0.5,,,,]; % Change the location of the tick marks on the plot
% by setting the XTick and YTick properties of the
% axes.
h.XTickLabel={'-3pi','-2pi','-pi','','pi','2pi','3pi'};
h.YTickLabel={'min=1','-0.5','','0.5','max=1'};

Specify tick mark labels by setting the XTickLabel and YTickLabel porperties of the axes, Set these properties using
a cell array of string with the desired labels .If you do not specify enough text labels for all the tick marks,then

MATLAB cycles through the labels.

4. grid on : to display the major grid lines, The grid on command sets the XGrid,YGrid,and ZGrid axes prperties.

5. grid minor: to display the minor grid lines,The grid minor command sets the XMinorGrid/YMinorGrid, and ZMinorGrid properties.

6. grid off : to remove the grid lines,

7.Display Grid Lines in Single Direction:

x=-10:10;
y=x.^2;
figure
plot(x, y);
ax=gca;
ax.XGrid='on'; % setting the XGrid axes property to 'on ' and the YGrid axes property to 'off'
ax.YGrid='off';
ax.XMinorGrid='on'; % setting the XGridMinor axes property to 'on ' and the YGridMinor axes
ax.YMinorGrid='off'; % property to 'off'

 8.Change Grid Line Style:

x=-10:10
y=x.^2;
figure
plot(x,y)
grid on
grid minor
ax=gca;
ax.GridLineStyle='-'; %change the grid line style using the GridLineStyle and
ax.MinorGridLineStyle='-'; %MinorGridLineStyle axes properties.

9.hold on: retain the line plot and add a new plot to the graph.

10.hold off: to reset the hold state so that new plots replace existing plot,which is the default behavior.

11.Create Graph with Two y-Axes:

A=;
a=0.005;
b=0.005;
t=:;
Z1=A*exp(-a*t);
Z2=sin(b*t);
[ax,p1,p2]=plotyy(t,Z1,t,Z2,'semilogy','plot');
ylabel(ax(),'Semilog Plot');
ylabel(ax(),'Linear Plot');
xlabel(ax(),'Time');
p1.LineStyle='--';
p1.LineWidth=;
p2.Linewidth=;
grid(ax(),'on');
grid(ax(),'on');

12.Display Markers at Specific Data Points on line Graph:

x=linspace(0,2*pi,100);
y=sin(x);
xmarkers=0:pi/2:2*pi;
ymarkers=sin(xmarkers);
figure
plot(x,y,'b',xmarkers,ymarkers,'b*');