| MATLAB® | ![]() |
| On this page… |
|---|
Suppose you plot the following data and want to create a graph that presents certain information about the data:
x = -10:.005:40; y = [1.5*cos(x)+4*exp(-.01*x).*cos(x)+exp(.07*x).*sin(3*x)]; plot(x,y)
This figure shows the graph created by the previous code.

Now, suppose you want to save copies of the graph by
Printing the graph on a local printer so you have a copy for your notebook
Exporting the graph to an Encapsulated PostScript® (EPS) file to incorporate into a word processor document
To obtain a better view, zoom in on the graph using horizontal zoom.
Enable zoom mode by clicking the Zoom tool
on the figure toolbar,
and then right-click to display the context menu. Select Horizontal
Zoom (2-D Plots Only) from Zoom Options.
You can reverse your zoom direction by doing Shift+left-click,
or using the context menu.

Left-click to zoom in on a region of the graph and use the Pan tool
to position the points
of interest where you want them on the graph.
Label some key points with data tips using the Data
Cursor tool
. Left-clicking the line
moves the last datatip you created to where you just clicked. To create
a new datatip, press Alt+click or use the tool's
context menu. See Data Cursor — Displaying Data Values Interactively in
the MATLAB Graphics documentation for more information on using
datatips.

Next, use the Figure Palette to annotate the plot. Choose the Double arrow tool in the Annotations section to draw a line between two datatips, as shown in the following figure.

Now, add a text box, also using the Figure Palette. You may have to scroll to see the text box icon. Drag out a box, and then type into it. You can stretch or shrink the box with its handles, and center the text with the Property Editor while the text box is selected. You can also use the Property Editor to change the text font, size, style, color, and also the text box line and background colors.

Finally, add text annotations, axis labels, and a title. You can add the title and axis labels using the following commands:
title ('y = 1.5cos(x) + 4e^{-0.01x}cos(x) + e^{0.07x}sin(3x)')
xlabel('X Axis')
ylabel('Y Axis')Note The text string passed to title uses TEX syntax to produce the exponents. See "Information About Using TEX" in the Text Properties reference page for more about using TEX syntax to produce mathematical symbols. |
You can also add these annotations by selecting the axes and typing the above strings into their respective fields in the Property Editor. The graph is now ready to print and export.

Before printing the graph, select File > Print Preview to view and modify how the graph will be laid out on the page. The Print Preview window opens, containing a tabbed control panel on its left side and a page image on its right side.
Click the Lines/Text tab, and enter a line of text in the Header Text edit field that you want to place at the top of the page. You can change the font, style, and size of the header by clicking the Font button beneath the text field, and also use the Date Style drop-down list to specify a date format to add the current date/time to the header.

The rulers along the left and top sides of the preview pane contain three black handlebars. The outside handlebars let you stretch one edge of the plot, leaving the other edges in place. The inner handlebars let you move the plot up and down or left and right without stretching it. Using them does not affect the figure itself, only the printed version of it.
You can also change the size and position of the plot on the page using the buttons and edit boxes on the Layout tab. You can revert to the original configuration by clicking the Auto (Actual Size, Centered) option button, and correct stretching and shrinking by clicking Fix Aspect Ratio. The following picture shows the Layout tab in Auto configuration.

By default, the locations of the axes tick marks are recalculated because a printed graph is normally larger than the one displayed on your monitor. However, you can keep your graph's tick marks and limits when printing it by clicking the Advanced tab and selecting Keep screen limits and ticks.
When you are ready to print your plot, click Print in the right pane. You can also click Close to accept the settings and dismiss the dialog box. Later, you can print the figure as you previewed it using Print on the figure's File menu. Both methods will open a standard Print dialog box, and will produce the same printed results.
Note There is no way to cancel a print preview; any changes you make will take effect if you print the figure. If you want to revert to a default page layout, you can generally accomplish this by selecting either the Use Defaults button or the Auto (Actual Size, Centered) option button on the Layout tab, although this will not affect every setting you can make. |
The Print Preview dialog box provides many other options for controlling how printed graphs look. Click its Help button for more information.
Exporting a graph is the process of creating a standard graphics file format of the graph (such as EPS or TIFF), which you can then import into other applications like word processors, drawing packages, etc.
This example exports the graph as an EPS file with the following requirements:
The size of the picture when imported into the word processor document should be 4 inches wide and 3 inches high.
All the text in the figure should have a size of 8 points.
To set the size, use the Export Setup dialog box (select Export Setup from the figure File menu). Then select 4 from the Width list and 3 from the Height list.

To set the font size of all the text in the graph, select Fonts in the Export Setup dialog box Properties selector. Then click Use fixed font size and enter 8 in the text box.

After you finish setting options for the exported graph, click the Export button. A standard Save As dialog box opens that enables you to specify a name for the file as well as select the type of file format you want to use.
The Save as type drop-down menu lists a number of other options for file formats. For this example, select EPS (*.eps) from the Save as type menu.
You can import the saved file into any application that supports EPS files.
You can also use the print command to print figures on your local printer or to export graphs to standard file types.
For More Information See the print command reference page and Printing and Exporting in the MATLAB Graphics documentation or select Printing and Exporting from the figure Help menu. |
![]() | Some Ways to Use Plotting Tools | Using Basic Plotting Functions | ![]() |
| © 1984-2008- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |