Parameters that Affect PrintingThe table below shows parameters that you can set before submitting your figure to the printer. The Parameter column lists all parameters that you can change. The Default column shows the MATLAB? default setting. The Dialog Box column shows which dialog box to use to set that parameter. If you can make this setting on only one platform, this is noted in parentheses: (W) for Windows?, and (U) for UNIX?. Some dialog boxes have tabs at the top to enable you to select a certain category. These categories are denoted in the table below using the format <dialogbox>/<tabname>. For example, Print Preview/Layout... in this column means to use the Print Preview dialog box, selecting the Layout tab. The print Command or set Property column shows how to set the parameter using the MATLAB print or set function. When usingprint, the table shows the appropriate command option (for example, print -loose). When using set, it shows the property name to set along with the type of object (for example, (Line) for line objects).
Selecting the FigureBy default, the current figure prints. If you have more than one figure open, the current figure is the last one that was active. To make a different figure active, click it to bring it to the foreground. Using MATLAB CommandsSpecify a figure handle using the command print -fhandle This example sends Figure No. 2 to the printer. A figure's number is usually its handle. print -f2 Selecting the PrinterYou can select the printer you want to use with the Print dialog box or with the print function. Using the Graphical User InterfaceUsing MATLAB CommandsYou can select the printer using the -P switch of the print function. This example prints Figure No. 3 to a printer called Calliope. print -f3 -PCalliope If the printer name has spaces in it, put single quotation marks around the -P option, as shown here. print '-Pmy local printer' Using a Network Print Server. On Windows systems, you can print to a network print server using the form shown here for a printer named trinity located on a computer named PRINTERS. print -P\\PRINTERS\trinity Setting the Figure Size and PositionThe default output figure size is 8 inches wide by 6 inches high, which maintains the aspect ratio (width to height) of the MATLAB figure window. The figure's default position is centered both horizontally and vertically when printed to a paper size of 8.5-by-11 inches. You can change the size and position of the figure: Using the Graphical User InterfaceSelect Print Preview from the figure window's File menu to open the Print Preview dialog box. Click the Layout tab to make changes to the size and position of your figure on the printed page. Use the text edit boxes on the left to enter new dimensions for your figure. Or, use the handlebars on the rulers in the right-hand pane to drag the margins and location of your figure with the mouse. The outer handlebars move the figure toward or away the nearest margin, while the central handlebar repositions the figure on the page without changing its proportions. Guidelines appear while you are using the handlebars. Settings you can change in the Layout tab are as follows: Placement. Choose whether you want the figure to be the same size as it is displayed on your screen, or you want to manually change its size using the options in the Layout pane. When you select the Use manual size and position mode, type the widths of any of the four margins and the preview image responds after each entry you make. Select units of measure (inches/centimeters/points) with pushbuttons on the Units section on the bottom of the pane. You can use the four buttons at the bottom of the Placement section to expand the figure to fill the page, make its aspect ratio (ratio of y-extent to x-extent) as printed match that of the figure, center the figure on the page, or restore the setup to what it was when you opened the Print Preview dialog. Selecting Fill page can alter the aspect ratio of your image. To get the maximum figure size without altering the aspect ratio, select Fix aspect ratio. Auto (actual size, centered). Select this option to center the figure on the page; it will be the same size as it is in the figure window. The four buttons below the control are dimmed when you select this option.
Using MATLAB CommandsTo print your figure with a specific size or position, make sure the PaperPositionMode property is set to manual (the default). Then set thePaperPosition property to the desired size and position. The PaperPosition property references a four-element row vector that specifies the position and dimensions of the printed output. The form of the vector is [left bottom width height] where
The default values for PaperPosition are [0.25 2.5 8.0 6.0] This example sets the figure size to a width of 4 inches and height of 2 inches, with the origin of the figure positioned 2 inches from the left edge of the paper and 1 inch from the bottom edge. set(gcf, 'PaperPositionMode', 'manual'); set(gcf, 'PaperUnits', 'inches'); set(gcf, 'PaperPosition', [2 1 4 2]); Setting the Paper Size or TypeSet the paper size by specifying the dimensions or by choosing from a list of predefined paper types. If you do not set a paper size or type, the default paper size of 8.5-by-11 inches is used. Paper-size and paper-type settings are interrelated—if you set a paper type, the paper size also updates. For example, if you set the paper type to US Legal, the width of the paper updates to 8.5 inches and the height to 14 inches. You can change the paper size and orientation: Using the Graphical User InterfaceSelect Print Preview from the figure window's File menu to open the Print Preview dialog box. Click the Layout tab to make changes to the paper type and orientation of the figure on the printed page. Settings you can change in the Layout tab are as follows: Paper Format, Units and Orientation. Select a paper type from the list under Format. If there is no paper type with suitable dimensions, enter your own dimensions in the Width and Height fields. Make sure Units is set appropriately to inches, centimeters, or points. If you change units after setting a paper width and height, the Width and Height fields update to use the units you just selected. The page region in the preview pane updates to show the new paper format or size when you change them. Use the Orientation buttons to select how you want the figure to be oriented on the printed page. The illustration under Setting the Paper Orientation shows the three types of orientation you can choose from.
Using MATLAB CommandsSet the PaperType property to one of the built-in MATLAB paper types, or set the PaperSize property to the dimensions of the paper. When you select a paper type, the unit of measure is not automatically updated. We recommend that you set the PaperUnits property first. For example, these commands set the units to centimeters and the paper type to A4. set(gcf, 'PaperUnits', 'centimeters'); set(gcf, 'PaperType', 'A4'); This example sets the units to inches and sets the paper size of 5-by-7 inches. set(gcf, 'PaperUnits', 'inches'); set(gcf, 'PaperSize', [5 7]); If you set a paper size for which there is no matching paper type, the PaperType property is automatically set to 'custom'. Setting the Paper OrientationPaper orientation refers to how the paper is oriented with respect to the figure. The choices are Portrait (the default), Landscape, andRotated. You can change the orientation of the figure: The figure below shows the same figure printed using the three different orientations.
Using the Graphical User Interface
Using MATLAB CommandsUse the PaperOrientation figure property or the orient function. Use the orient function if you always want your figure centered on the paper. The following example sets the orientation to landscape: set(gcf, 'PaperOrientation', 'landscape'); Centering the Figure. If you set the PaperOrientation property from portrait to either of the other two orientation schemes, you might find that what was previously a centered image is now positioned near the paper's edge. You can either adjust the position (use thePaperPosition property), or you can use the orient function, which always centers the figure on the paper. The orient function takes the same argument names as PaperOrientation. For example, orient rotated; Selecting a RendererA renderer is software and/or hardware that processes graphics data (such as vertex coordinates) to display, print, or export a figure. You can change the renderer from the one used to draw a figure to another renderer when printing it: Supported RenderersMATLAB supports three rendering methods with the following characteristics:
For more detailed information about changing rendering methods, see the Figure Renderer property. Hardware vs. Software OpenGL ImplementationsThere are two kinds of OpenGL implementations: hardware and software.
OpenGL AvailabilityOpenGL is available on all computers that run MATLAB. MATLAB automatically finds hardware-accelerated versions of OpenGL if such versions are available. If the hardware-accelerated version is not available, then MATLAB uses the software version (except on Macintosh systems, which do not support software OpenGL). The following software versions are available:
MATLAB issues a warning if it cannot find a usable OpenGL library. Selecting Hardware-Accelerated or Software OpenGLMATLAB enables you to switch between hardware-accelerated and software OpenGL. However, Windows and UNIX systems behave differently:
If you do not want to use hardware OpenGL, but do want to use object transparency, you can issue the following command. opengl software This command forces MATLAB to use software OpenGL. Software OpenGL is useful if your hardware-accelerated version of OpenGL does not function correctly and you want to use image, patch, or surface transparency, which requires the OpenGL renderer. To reenable hardware OpenGL, use the command: opengl hardware on Windows systems or restart MATLAB on UNIX systems. By default, MATLAB uses hardware-accelerated OpenGL. See the opengl reference page for additional information Determining What Version You Are UsingTo determine the version and vendor of the OpenGL library that MATLAB is using on your system, type the following command at the MATLAB prompt: opengl info The returned information contains a line that indicates if MATLAB is using software (Software = true) or hardware-accelerated (Software = false) OpenGL. This command also returns a string of extensions to the OpenGL specification that are available with the particular library MATLAB is using. This information is helpful to MathWorks?, so please include this information if you need to report bugs. Note that issuing the opengl info command causes MATLAB to initialize OpenGL. OpenGL vs. Other MATLAB RenderersThere are some differences between drawings created with OpenGL and those created with other renderers. The OpenGL specific differences include
The Default MATLAB RendererBy default, OpenGL tries to optimize the rendering method based on the attributes of the figure (its complexity and the settings of various Handle Graphics? properties) and in some cases, the printer driver or file format used. In general, renderers are selected as follows:
The RendererMode property describes whether to automatically select the renderer based on the contents of the figure (when set to auto), or to use the Renderer property that you have indicated (when set to manual). Reasons for Manually Setting the RendererTwo reasons to set the renderer yourself are
Using the Graphical User Interface
Using MATLAB CommandsYou can use the Renderer property or a switch with the print function to set the renderer for printing or exporting. These two lines each set the renderer for the current figure to Z-buffer. set(gcf, 'Renderer', 'zbuffer'); or print -zbuffer The first example saves the new value of Renderer with the figure; the second example only affects the current print or export operation. When you set the Renderer property, the RendererMode property is automatically reset from auto (the factory default) to manual. Setting the ResolutionResolution refers to how accurately your figure is rendered when printed or exported. Higher resolutions produce higher quality output. The specific definition of resolution depends on whether your figure is output as a bitmap or as a vector graphic. You can change the resolution used to print a figure: Default Resolution and When You Can Change ItThe default resolution depends on the renderer used and the graphics format or printer driver specified. The following two tables summarize the default resolutions and whether you can change them. Resolutions Used with Graphics Formats
Resolutions Used with Printer Drivers
Choosing a SettingYou might need to determine your resolution requirements through experimentation, but you can also use the following guidelines. For Printing. The default resolution of 150 dpi is normally adequate for typical laser-printer output. However, if you are preparing figures for high-quality printing, such as a textbook or color brochures, you might want to use 200 or 300 dpi. The resolution you can use can be limited by the printer's capabilities. For Exporting. If you are exporting your figure, base your decision on the resolution supported by the final output device. For example, if you will import your figure into a word processing document and print it on a printer that supports a maximum resolution setting of 300 dpi, you could export your figure using 300 dpi to get a precise one-to-one correspondence between pixels in the file and dots on the paper. Impact of Resolution on Size and Memory NeededResolution affects file size and memory requirements. For both printing and exporting, the higher the resolution setting, the longer it takes to render your figure. Using the Graphical User InterfaceTo set the resolution for built-in MATLAB printer drivers:
Using MATLAB CommandsIf you use a Windows printer driver, you can only set the resolution using the Windows Document Properties dialog box. Otherwise, to set the resolution for printing or exporting, the syntax is print -rnumber where number is the number of dots per inch. To print or export a figure using screen resolution, set number to 0 (zero). This example prints the current figure with a resolution of 100 dpi: print -r100 This example exports the current figure to a TIFF file using screen resolution: print -r0 -dtiff myfile.tif Setting the Axes Ticks and LimitsThe default output size, 8-by-6 inches, is normally larger than the screen size. If the size of your printed or exported figure is different from its size on the screen, the number and placement of axes tick marks scale to suit the output size. This section shows you how to lock them so that they are the same as they were when displayed. You can change the resolution used when printing a MATLAB figure: Using the Graphical User InterfaceSelect Print Preview from the figure window's File menu to open the Print Preview dialog box. Select the Advanced tab to make changes to the axes, UI controls, or renderer settings. Settings you can change in the Advanced tab are as follows, by panel: Axes limits and ticks. If the size of your printed or exported figure is different from its size on the screen, the number and placement of axes tick marks scale to suit the output size. Select Keep screen limits and ticks to lock them so that they are the same as they were when displayed. If you want to automatically adjust the ticks and limits when scaling for printing, select Recompute limits and ticks. Miscellaneous. Use the Renderer drop-down menu to specify which renderer to use in printing the figure. Set the renderer to Painters,Z-buffer, or OpenGL, or select auto to automatically decide which one to use, depending on the characteristics of the figure. (SeeSelecting a Renderer). Use the Resolution drop-down menu to specify the resolution, in dots per inch (DPI), at which to render and print the figure. You can select150, 300, or 600 DPI, or type in a different value (positive integer). Figure UI Controls. By default, user interface controls are included in your printed or exported figure. Clear the Print UIControls check box to exclude them. (See Excluding User Interface Controls from Printed Output).
Using MATLAB CommandsTo set the XTickMode, YTickMode, and ZTickMode properties to manual, type set(gca, 'XTickMode', 'manual'); set(gca, 'YTickMode', 'manual'); set(gca, 'ZTickMode', 'manual'); Setting the Background ColorYou can keep the background the same as is shown on the screen when printed, or change the background to white. There are two types of background color settings in a figure: the axes background and the figure background. The default displayed color of both backgrounds is gray, but you can set them to any of several colors. Regardless of the background colors in your displayed figure, by default, they are always changed to white when you print or export. This section shows you how to retain the displayed background colors in your output. Using the Graphical User InterfaceTo retain the background color on a per figure basis:
If you are exporting your figure using the clipboard, use the Copy Options panel of the Preferences dialog box. Using MATLAB CommandsTo retain your background colors, use set(gcf, 'InvertHardCopy', 'off'); The following example sets the figure background color to blue, the axes background color to yellow, and then sets InvertHardCopy tooff so that these colors appear in your printed or exported figure. set(gcf, 'color', 'blue'); set(gca, 'color', 'yellow'); set(gcf, 'InvertHardCopy', 'off'); Setting Line and Text CharacteristicsIf you transfer your figures to Microsoft? Word or PowerPoint? applications, you can set line and text characteristics to values recommended for those applications. The Figure Copy Template Preferences dialog box provides Word and PowerPoint options to make these settings, or you can set certain line and text characteristics individually. You can change line and text characteristics: Using the Graphical User InterfaceTo open Figure Copy Template Preferences, select Preferences from the File menu, and then click Figure Copy Template in the left pane. Settings you can change in the Figure Copy Template Preferences dialog box are as follows: Microsoft Word or PowerPoint. Click Documents or Presentations to apply recommended MATLAB settings. Text. Use options under Text to modify the appearance of all text in the figure. You can change the font size, change the text color to black and white, and change the font style to bold. Lines. Use the Lines options to modify the appearance of all lines in the figure:
UIControls and axes. If your figure includes user interface controls, you can choose to show or hide them by clicking Show uicontrols. Also, to keep axes limits and tick marks as they appear on the screen, click Keep axes limits and tick spacing. To allow automatic scaling of axes limits and tick marks based on the size of the printed figure, clear this box.
Using MATLAB CommandsYou can use the set function on selected graphics objects in your figure to change individual line and text characteristics. For example, to change line width to 1.8 and line style to a dashed line, use lineobj = findobj('type', 'line'); set(lineobj, 'linewidth', 1.8); set(lineobj, 'linestyle', '--'); To change the font size to 15 points and font weight to bold, use textobj = findobj('type', 'text'); set(textobj, 'fontunits', 'points'); set(textobj, 'fontsize', 15); set(textobj, 'fontweight', 'bold'); Setting the Line and Text ColorWhen colored lines and text are dithered to gray by a black-and-white printer, it does not produce good results for thin lines and the thin lines that make up text characters. You can, however, force all line and text objects in the figure to print in black and white, thus improving their appearance in the printed copy. When you select this setting, the lines and text are printed all black or all white, depending on the background color. The default is to leave lines and text in the color that appears on the screen.
You can change the resolution used to print a figure: Using the Graphical User InterfaceSelect Print Preview from the figure window's File menu to open the Print Preview dialog box. Select the Lines and Text tab to make changes to the color of all lines and text on the printed page. The controls for the Lines and Text tab are shown below: Settings you can change in Lines and Text are as follows: Lines. The default option in this panel causes lines to print at the same width they are portrayed in the figure window. You can scale line width from 0 percent upwards for printing using the Scale By field. To print lines at a particular point size, select Custom. All lines on the plot will be the same weight when you use the Custom option; the Scale By option respects relative line weight. When you scale lines downward, you can prevent them from becoming too faint by setting the Min Width option to Custom and specifying a minimum line width in points in that field. Text. The default is to print text in the same font and at the same size as it is in the figure. To change the font (for all text) select Customand choose a new font from the drop-down list that is then enabled. Scale the font size using the Scale By option. To print text at a particular point size, select Custom. All text on the plot will be printed at the point size you specify when you use the Custom option; theScale By option respects relative font size. You can specify the Font Weight (normal, light, demi, or bold) and Font Angle (normal, italic, or oblique) for all text as well, using the drop-down menus at the bottom of the Text panel. Header. Type any text that you want to appear at the top of the printed figure in the Header Text edit field. If you want today's date and/or time appended to the header text, select the appropriate format from the Date Style popup menu. To specify and style the header font (which is independent of the font used in the figure), click the Font button and choose a font name, size, and style from the Font selection window that appears.
Using MATLAB CommandsThere is no equivalent MATLAB command that sets line and text color depending on background color. Set the color of lines and text using the set function on either line or text objects in your figure. This example sets all lines and text to black: set(findobj('type', 'line'), 'color', 'black'); set(findobj('type', 'text'), 'color', 'black'); Specifying a Colorspace for Printing and ExportingBy default, color output is in the RGB color space (red, green, blue). If you plan to publish and print MATLAB figures using printing industry standard four-color separation, you might want to use the CMYK color space (cyan, magenta, yellow, black). Using the Windows Graphical User InterfaceSelect Print Preview from the figure window's File menu to open the Print Preview dialog box. Select the Color tab to make changes to the color of all lines and text on the printed page. The controls for the Color tab are shown below: You can print the contents of your figure in color, grayscale, or black-and-white by selecting the appropriate button in the panel. When you select Color, you can choose between an RGB (red/green/blue) or a CMYK (cyan/magenta/yellow/black) color specification, if your printer is capable of it. Independently of the Color Scale controls, you can specify a Background color for printing. Select Same as figure to use the color used in the figure itself (default is gray), or specify a Custom color from the combo box popup menu. The choices are black, white, and several RGB color triplet values; you type any valid MATLAB colorspec in this field as well, such as g, magenta, or .3 .4 .5. The background color you specify is respected even if you choose Black and White or Gray Scale in the Color Scale panel. Using the Graphical User Interface on UNIX PlatformsOn any platform, you can also indicate whether to print in color, grayscale or black-and-white with the Print Preview dialog box. Using MATLAB CommandsUse the -cmyk option with the print function. This example prints the current figure in CMYK using a PostScript Level II color printer driver. print -dpsc2 -cmyk Excluding User Interface Controls from Printed OutputUser interface controls are objects that you create and add to a figure. For example, you can add a button to a figure that, when clicked, conveniently runs another MATLAB file. By default, user interface controls are included in your printed or exported figure. This section shows how to exclude them. Using the Graphical User Interface
Using MATLAB CommandsUse the -noui switch. This example specifies a color PostScript driver and excludes UI controls. print -dpsc -noui This example exports the current figure to a color EPS file and excludes UI controls. print -depsc -noui myfile.eps Producing Uncropped FiguresIn most cases, MATLAB crops the background tightly around the objects in the figure. Depending on the printer driver or file format you use, you might be able to produce uncropped output. An uncropped figure has increased background area and is often desirable for figures that contain UI controls. The setting you make changes the PostScript BoundingBox property saved with the figure. Using MATLAB CommandsUse the -loose option with the print function. On Windows platforms, the uncropped option is only available if you print to a file. This example exports the current figure, uncropped, to an EPS file. print -deps -loose myfile.eps |
|
来自: windycityboy > 《GUI》