| MATLAB® | ![]() |
| On this page… |
|---|
This example illustrates how to use the plotting tools to graph a workspace variable versus an expression typed into the Add Data to Axes dialog.
Create a variable in the workspace,
x = -2*pi:pi/25:2*pi;
Use the plottools command to create a figure group with the plotting tools attached.
plottools
Click 2D Axes in the New Subplot panel of the Figure Palette.

Once the axes appears, the Add Data button on the Plot Browser is activated.

Click this button to display the Add Data to Axes dialog. When the Add Data to Axes dialog is displayed, enter the following values:
Select plot as the Plot Type.
Set X Data Source to x.
Set Y Data Source to sin(x).^2.
Click OK to plot this data.

A plot of sin(x).^2 versus x appears.
Now add another plot to the same axes. Click Add Data again and specify the data to plot:
Set X Data Source to x.
Set Y Data Source set to sin(x).^8.
Click OK to plot this data.
Select the last plot (the green line) and set the Plot Type in the Property Editor to Stem. The plot should now look like the following picture.

Add a second axes below the current axes using the New Subplots panel. Click the right-facing arrowhead next to 2D Axes and move the mouse to darken two squares, one on top of the other.
This creates a subplot axes below the existing axes. The existing axes resize so both fit in the figure.

In the inserted axes, select its entry in the Plot Browser and then click Add Data.
When the Add Data to Axes dialog is displayed, enter the following values:
Set X Data Source to x.
Set Y Data Source to sin(x).^3.
Click OK to plot this data.
Now add another plot overlaid on the first by clicking Add Data again and specify the data to plot:
Set X Data Source to x.
Set Y Data Source to sin(x).^9.
Click OK to plot this data.
Select the plot labeled sin(x).^9 under the second axes in the Plot Browser. Set the Plot Type in the Property Editor to Area.
Adjust the x-axis in both axes using the Property Editor.
Select the first axes in the Plot Browser.
Change X Limits to -7 and 7.
Repeat these steps for the second axes.
Select the first axes in the Plot Browser and set the following properties in the Property Editor:
Set Title to Even Powers.
Set X Label to X.
Click the Y Axis tab and set Y Label to Sine of X.
Select the second axes in the Plot Browser and set the following properties in the properties panel:
Set Title to Odd Powers.
Set X Label to X.
On the Y Axis tab, set Axis label to Sine of X.
Note that the Plot Browser reflects the new axes names.
The following picture shows the result of these steps.

Select the text of the y-axis label on the first axes (now labeled Even Powers in the Plot Browser) and click the More Properties button on the Property Editor. Set the Rotation property to 0 and reposition the text by hand.
To make more space for the y-axis label, which is now in a horizontal position, select the axes and move it to the right with the mouse.
Repeat this process for the second axes (labeled Odd Powers in the Plot Browser).
The repositioned text label now looks like the following picture.

Note You can always undo your last change to the graph by selecting Undo from the Edit menu. |
![]() | Plotting Tools — Interactive Plotting | Example — Plotting from the Figure Palette | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |