# 3.5: Plotting Points


If the output of your program is a long stream of numbers, it can be hard to see what is happening. Plotting the results can make things clearer.

The plot function is a versatile tool for plotting two-dimensional graphs. Unfortunately, it’s so versatile that it can be hard to use (and hard to read the documentation). We’ll start simple and work our way up.

To plot a single point, type

>> plot(1, 2, 'o')

A Figure Window should appear with a graph and a single blue circle at $$x$$ position 1 and $$y$$ position 2.

The letter in single quotes is a style string that specifies how the point should be plotted; o indicates a circle. Other shapes include +, *, x, s (for a square), d (for a diamond), and ^ (for a triangle).

You can also specify the color by starting the style string with a color code:

>> plot(1, 2, 'ro')

Here, r stands for red; the other colors include g for green, b for blue, c for cyan, m for magenta, y for yellow, and k for black.

When you use plot this way, it can only plot one point at a time. If you run plot again, it clears the figure before making the new plot. The hold command lets you override that behavior: hold on tells MATLAB not to clear the figure when it makes a new plot; hold off returns to the default behavior.

Try this:

>> clf
>> hold on
>> plot(1, 1, 'ro')
>> plot(2, 2, 'go')
>> plot(3, 3, 'bo')
>> hold off

The clf command clears the figure before we start plotting.

If you run the code above, you should see a figure with three circles. MATLAB scales the plot automatically so that the axes run from the lowest values in the plot to the highest.

##### Exercise $$3.2$$

Modify bikeloop.m so that it clears the figure before running the loop. Then, each time through the loop, it should plot the value of b versus the value of i with a red circle.

Once you get that working, modify it so it plots the values of c with blue diamonds.

This page titled 3.5: Plotting Points is shared under a CC BY-NC-SA 4.0 license and was authored, remixed, and/or curated by Carey Smith via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.