# Matlab Basic Plotting Commands

DISCLAIMER: there have been many changes over the years to plotting commands, especially starting with MATLAB R2014b (for details, see this Graphics Changes in R2014b PDF from MathWorks). I try to modify these pages and examples as needed, but they may not always reflect the latest changes. The following were first created in 2011 and updated using MATLAB R2016a.

Loyola peeps: There are many examples on the H-drive!

Useful and common commands for creating different 2D and 3D plots (not a complete list!)

`plot(x,y)`

`plot3(x,y,z)`

`mesh(x,y,z)`

`surf(x,y,z)`

`[x,y]=meshgrid(xd,yd);`

`title('Title text')`

`xlabel('x-axis label'), ylabel('y-axis label')`

, etc.`plot3(x,y,z, 'r:')`

will create a red graph with dotted line.`plot3(x,y,z, 'k', 'LineWidth', 2)`

will make the line black and thicker`xlim([-2,2]), zlim([-10,10])`

, etc. can set the limit for the axes`axis([xmin, xmax, ymin, ymax, zmin, zmax])`

can set limits all at once for all axes`axis equal, axis tight, axis square`

, etc.`grid on`

`hold on`

AND`hold off`

`legend('legend 1', 'legend 2', ...)`