Page 97 - A Guide to MATLAB for Beginners and Experienced Users
P. 97

78        Chapter 5: MATLAB Graphics


           Customizing and Manipulating

           Graphics


                      This is a more advanced topic; if you wish you can skip it on a first reading.

                     So far in this chapter, we have discussed the most commonly used MATLAB
                     routines for generating plots. But often, to get the results one wants, one needs
                     to customize or manipulate the graphics these commands produce. Knowing
                     how to do this requires understanding a few basic principles concerning the
                     way MATLAB stores and displays graphics. For most purposes, the discussion
                     here will be sufficient. But if you need more information, you might eventually
                     want to consult one of the books devoted exclusively to MATLAB graphics,
                     suchas Using MATLABGraphics, which comes free (in PDF format) with
                     the software and can be accessed in the “MATLAB Manuals” subsection of
                     the “Printable Documentation” section in the Help Browser (or under “Full
                     Documentation Set” from the helpdesk in MATLAB 5.3 and earlier versions),
                     or Graphics and GUIs with MATLAB, 2nd ed., by P. Marchand, CRC Press,
                     Boca Raton, FL, 1999.
                       In a typical MATLAB session, one may have many figure windows open
                     at once. However, only one of these can be “active” at any one time. One can
                     find out whichfigure is active withthe command gcf, short for “get current
                     figure,” and one can change the active figure to, say, figure number 5 with the
                     command figure(5), or else by clicking on figure window 5 withthe mouse.
                     The command figure (withno arguments) creates a blank figure window.
                     (This is sometimes useful if you want to avoid overwriting an existing plot.)
                       Once a figure has been created and made active, there are two basic ways to
                     manipulate it. The active figure can be modified by MATLAB commands in the
                     command window, suchas the commands title and axis square that we
                     have already encountered. Or one can modify the figure by using the menus
                     and/or tools in the figure window itself. Let’s consider a few examples. To insert
                     labels or text into a plot, one may use the commands text, xlabel, ylabel,
                     zlabel, and legend, in addition to title. As the names suggest, xlabel,
                     ylabel, and zlabel add text next to the coordinate axes, legend puts a
                     “legend” on the plot, and text adds text at a specific point. These commands
                     take various optional arguments that can be used to change the font family
                     and font size of the text. As an example, let’s illustrate how to modify our plot
                     of the lemniscate (Figure 5-3) by adding and modifying text:

                       >> figure(3)
                       >> title(’The lemniscate xˆ2-yˆ2=(xˆ2+yˆ2)ˆ2’,...
   92   93   94   95   96   97   98   99   100   101   102