1. Trang chủ >
  2. Công Nghệ Thông Tin >
  3. Kỹ thuật lập trình >

2 Options for Form, Ranges, and Fonts

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (18.67 MB, 1,135 trang )


Chapter 7 • Graphics Options



185



‡ Global Options



The following options can be used to adjust some global aspects of a plot.

Options for form and size:

** AspectRatio Ratio of height to width of the plotting rectangle; examples of values:

1/GoldenRatio c , Automatic



gp



, Full, 0.4



ImageSize The absolute size (in printer’s points) of the plot; examples of values: Automatic, Full,

All, width, {width, height}, {maxsize}, {{maxwidth}, {maxheight}}



Options for plot range:

** PlotRange Ranges for x and y in the plot; examples of values:

Automatic



p



c



{ymin, Automatic}



{Full, Automatic}



{ymin, All}



{{xmin, xmax}, Automatic}



Full



{All, ymax}



{Full, {ymin, Automatic}}



5



{ymin, ymax}



{{xmin, xmax}, {ymin, ymax}}



All



g



(PlotRangeClipping (Ÿ6) Whether graphics objects should be clipped at the edge of the region

defined by PlotRange or should be allowed to extend to the selection rectangle; possible values:

True c p , False g )

Options for margins:

PlotRegion Specifies margins around the plot inside the selection rectangle; examples of values:

Automatic (means {{0, 1}, {0, 1}}), {{xmin, xmax}, {ymin, ymax}}

(ImageMargins Specifies margins (in printer’s points) outside the selection rectangle; examples of

values: 0, Automatic, 15, {{left, right}, {bottom, top}})

Background Color of the background; examples of values: None, LightGray

(ImagePadding (Ÿ6) Extra space (in printer’s points) for objects such as thick lines and tick and axes

labels; examples of values: All, None, 15, {{left, right}, {bottom, top}})

(PlotRangePadding (Ÿ6) How much farther axes etc. should extend beyond the range of coordinates specified by PlotRange; examples of values: Automatic, None, {0.2, 0.5})



Options for fonts and formatting:

* BaseStyle (Ÿ6) Style of all texts; examples of values: {}, {9, "Bold", FontFamily Ø "Arial"}

LabelStyle (Ÿ6) Style of all labels; examples of values: {}, {9, "Bold", FontFamily Ø "Arial"}

(FormatType Format type of text used in a plot; examples of values: TraditionalForm,

StandardForm, InputForm, OutputForm)

Miscellaneous options:

(BaselinePosition (Ÿ6) Where the baseline of a plot should be if the plot is combined with other

plots or text; examples of values: Automatic, Axis, Bottom, Top, Center, Baseline)

(AlignmentPoint (Ÿ6) How objects should by default be aligned when they appear in Inset;

default value: Center)

(ContentSelectable (Ÿ6) Whether and how content of a plot should be selectable; possible values:

Automatic (double-click allows content selection), True (single clicks immediately select content

objects), False (content objects cannot be selected))

(PreserveImageOptions (Ÿ6) Whether the size and margins of a plot should remain the same if the

plotting command is executed anew; examples of values: Automatic (the properties should remain

the same if not explicitly otherwise stated), True (the properties should remain the same), False

(the previous properties are ignored))

(DisplayFunction Function to apply to a graphic; default value: $DisplayFunction)



186



Mathematica Navigator



‡ Local Options



The following options can be used to adjust some local components of a plot.

An option for plot label:

PlotLabel Label of the plot; examples of values: None, Sin[x/2], "Function g(x)"



Options for axes and ticks:

* Axes Whether to draw the axes; examples of values: True c p , False g , {True, False}

* AxesOrigin Point where the axes cross; examples of values: Automatic, {0, 0}

AxesLabel Labels for the axes; examples of values: None, y, {x, None}, {x, y}

(AxesStyle Style of the axes, axes labels, tick marks, and tick labels; examples of values: {}, Thick,

Blue, Arrowheads[0.07], Directive[Thick, Blue, 12, Italic]

** Ticks Tick on the axes; simple examples of values: Automatic, None, {{p, 2p}, Automatic},

{Automatic, {-1, 0, 1}}, {{p, 2p}, {-1, 0, 1}}

TicksStyle (Ÿ6) Style of tick marks and tick labels; examples of values: {}, Blue,

Directive[Thick, Blue, 12]



Options for frame and frame ticks:

* Frame Whether to draw a frame; examples of values: False, True, {True, True, False, False}

* FrameLabel Labels for the frame; examples of values: None, {x, y}, {"bottom", "left", "top",

"right"}

* RotateLabel Whether to rotate the labels for the vertical edges; possible values: True, False

FrameStyle Style of the frame, frame labels, frame tick marks, and frame tick labels; examples of



values: Automatic, Blue, Directive[Thick, Red, 12, Italic]

* FrameTicks Frame tick marks on the frame; simple examples of values: Automatic, None, All (on



all edges), {{0, p, 2p}, {-1, 1}, None, None}

FrameTicksStyle (Ÿ6) Style of frame tick marks and frame tick labels; examples of values: {}, Red,

Directive[Thick, Red, 12, Bold]



Options for grid lines:

GridLines How the grid lines are drawn; simple examples of values: None, Automatic, {None,

Automatic}, {None, {-1,0,1}}, {{0,1,2}, {-1,0,1}}

(GridLinesStyle (Ÿ6) Style of the grid lines; examples of values: {}, Dashed,

Directive[LightGray, Dashed])

Options for primitives:

(Prolog Graphics primitives to be plotted before the main plot; examples of values: {}, {Red,

PointSize[Medium], Point[{3, 2}]})

* Epilog Graphics primitives to be plotted after the main plot; examples of values: {}, {Red,

PointSize[Medium], Point[{3, 2}]}



Chapter 7 • Graphics Options



187



‡ Options for the Curve



With Plot and ParametricPlot, the following options can be used to adjust the curve to be plotted.

Options for plot style:

* PlotStyle c p Style(s) of the curve(s); examples of values: Automatic, Thickness[Medium],

Directive[Thick, Red, Dashed]



(ClippingStyle c (Ÿ6) How to indicate clipped parts that fall outside of the plot range; examples

of values: None, Automatic, Red, {Blue, Red})

Options for color function:

(ColorFunction c p (Ÿ6) Function that determines the color of the curve; examples of values:

Automatic, (Hue[#2] &), (RGBColor[#2, 0, 1 - #2] &), "Rainbow")

(ColorFunctionScaling c p (Ÿ6) Whether arguments to a color function should be scaled to lie

between 0 and 1; examples of values: True, False)

Options for filling:

c

(Ÿ6) Type of filling to use; examples of values: None, Axis, Bottom, Top, 0.3, True

(FillingStyle c (Ÿ6) Style of filling; examples of values: Automatic, Red, {Blue, Red} (different

style for negative and positive values), Directive[Opacity[0.3], Blue])

Filling



Options for mesh:

Mesh c p How many mesh points should be drawn; examples of values: None c , Automatic p , 10,

Full, All, {{0}}

MeshFunctions c p (Ÿ6) How to determine the placement of the mesh points; examples of values:

{#1 &} c , Automatic p , {#2 &}

MeshStyle c p The style of mesh points; examples of values: Automatic, PointSize[Small],

Directive[Red, PointSize[Medium]]



(MeshShading

Blue})



cp



(Ÿ6) How to shade regions between mesh points; examples of values: None, {Red,



Options for exclusions:

Exclusions c p (Ÿ6) The x points that are excluded in plotting; examples of values: Automatic,

None, {p/2, 3 p/2}, {Cos[x] ã 0}

ExclusionsStyle c p (Ÿ6) What to draw at excluded points; examples of values: None,

Directive[Blue, Dashed], {None, Directive[Red, PointSize[Medium]]}

(RegionFunction c p (Ÿ6) Specifies the region to include in the plot drawn; examples of values:

(True &), (Abs[#2] > 0.7&))

Options for plotting algorithm:

PlotPoints c p Number of initial sampling points; examples of values: Automatic, 100

MaxRecursion c p (Ÿ6) The maximum number of recursive subdivisions allowed; examples of

values: Automatic, 8

WorkingPrecision c p (Ÿ6) The precision used in computations; examples of values:

MachinePrecision, 20

(Evaluated c p (Ÿ6) Whether the expression to be plotted is evaluated before the expression is

sampled; possible values: Automatic, True, False)

(PerformanceGoal c p (Ÿ6) What aspect of performance to try to optimize; examples of values:

$PerformanceGoal, "Quality", "Speed")

(EvaluationMonitor c p (Ÿ6) Expression to evaluate at every function evaluation; examples of

values: None, Sow[{x, Sin[x]}])



188



Mathematica Navigator



In various style options we can use graphics primitives such as Point, Line, and Text and graphics

directives such as AbsolutePointSize, Thick, Dashed, Gray, or Red. These are explained in Chapter 6.

All of the options are explained in detail in the remaining sections of this chapter, after we have

considered the combination of various styles. Note that in the PlotLegends` package we have options for

legends.

‡ Combining Styles



The styles of various components of a plot can be defined with several options: PlotStyle,

ClippingStyle, FillingStyle, MeshStyle, ExclusionsStyle, LabelStyle, AxesStyle, TicksStyle,

FrameStyle, FrameTicksStyle, and GridLinesStyle. As an example, consider PlotStyle:

GraphicsRow@8Plot@8Sin@xD, Cos@xD<, 8x, 0, 2 p<, PlotStyle Ø ThickD,

Plot@8Sin@xD, Cos@xD<, 8x, 0, 2 p<, PlotStyle Ø 8Thick, Blue
Plot@8Sin@xD, Cos@xD<, 8x, 0, 2 p<, PlotStyle Ø 88Thick, Blue<
Plot@8Sin@xD, Cos@xD<, 8x, 0, 2 p<,

PlotStyle Ø 88Thick, Blue<, 8Thick, Red<
1.0

0.5

-0.5

-1.0



1.0

0.5

1 2 3 4 5 6



1.0

0.5

1 2 3 4 5 6



-0.5

-1.0



1.0

0.5

1 2 3 4 5 6



-0.5

-1.0



-0.5

-1.0



1 2 3 4 5 6



In these four plots, examine the use of braces in the value of PlotStyle. In the first plot, we have

only one directive, Thick, and it is applied for both curves. In the second plot, we have two directives

inside single braces, and now the first directive, Thick, defines the style of the first curve and the second

directive, Blue, the style of the second curve. If we want both curves to be blue and thick, we have to

use double braces, as is done in the third plot. If we want unique styles for both curves, we use a nested

list for the directives, as can be seen in the fourth plot.

It may be difficult to remember when to use single braces and when to use double braces. The use of

Directive may then be helpful.

Directive[dir1, dir2, … ] (Ÿ6) Represents a single graphics directive composed of the given



directives

Thus, with Directive we can collect together several directives and use the collection like a single

directive. The third and fourth plots can now be written as follows:

8Plot@8Sin@xD, Cos@xD<, 8x, 0, 2 p<, PlotStyle Ø Directive@Blue, ThickDD,

Plot@8Sin@xD, Cos@xD<, 8x, 0, 2 p<,

PlotStyle Ø 8Directive@Blue, ThickD, Directive@Red, ThickD


:



1.0



1.0



0.5



0.5

1



2



3



4



5



6



,



1



-0.5



-0.5



-1.0



-1.0



2



3



4



5



6



>



As can be seen, with Directive we need single braces only if we define different styles for each of

several curves, and double braces are not needed at all. As another example, consider defining the style

of a frame:



Chapter 7 • Graphics Options



189



8Plot@Sin@xD, 8x, 0, 2 p<, Frame Ø True,

FrameStyle Ø 88Thick, Blue<, 8Thick, Blue<, 8Thick, Blue<, 8Thick, Blue<
Plot@Sin@xD, 8x, 0, 2 p<, Frame Ø True, FrameStyle Ø Directive@Thick, BlueDD<

1.0



:



1.0



0.5



0.5



0.0



>



0.0



,



-0.5



-0.5



-1.0



-1.0

0



1



2



3



4



5



6



0



1



2



3



4



5



6



In the first plot, we had to separately define the style of each edge of the frame, whereas in the

second plot the use of Directive enables us to define the style only once.

We will use Directive in this book to collect several directives together, but if you are comfortable

with the braces, they can often also be used.



7.2 Options for Form, Ranges, and Fonts

7.2.1 Form and Size

** AspectRatio Ratio of height to width of the plotting rectangle; examples of values:

1/GoldenRatio c , Automatic



gp



, Full, 0.4



The default value 1/GoldenRatio = 0.618 of AspectRatio for Plot gives an aesthetically pleasing

form. The default value Automatic of AspectRatio for Graphics and ParametricPlot sets one unit on

the x axis to have the same length as one unit on the y axis. The aspect ratio can be any positive real

number. The value Full means that the graphic should be stretched so as to fill out its enclosing region

in Grid or related construct. Next, we plot a circle with each of the three commands. The curve produced by Plot looks like an ellipse because of the aspect ratio 0.618:

GraphicsRow@8Plot@8Sqrt@1 - x ^ 2D, -Sqrt@1 - x ^ 2D<, 8x, -1, 1
ParametricPlot@8Cos@tD, Sin@tD<, 8t, 0, 2 p
Graphics@Circle@D, Axes Ø TrueD<, ImageSize Ø 330D

1.0

0.5

-1.0 -0.5

-0.5

-1.0



0.5



1.0



1.0



1.0



0.5



0.5



-1.0 -0.5

-0.5

-1.0



0.5



1.0



-1.0 -0.5

-0.5



0.5



1.0



-1.0



ImageSize The absolute size (in printer’s points) of the plot; examples of values: Automatic, Full,

All, width, {width, height}, {maxsize}, {{maxwidth}, {maxheight}}



The size of the plot is easy to change with the mouse, but we can also use the ImageSize option. It

determines the absolute size of the plot in units of printer’s points (1 ê 72 inch). One number as the value

of the option defines the width, and a list of two numbers determines both the width and the height.

Note that if both the width and the height are specified, the plot fills this area only if the aspect ratio is

exactly height/width. The default size can be changed with the Option Inspector.



190



Mathematica Navigator



The value Full for ImageSize means that on the screen, the size of the graphic is automatically

adjusted to fit the window and, when printed, the graphic has the full width of the content area of the

page. The aspect ratio of a plot is kept fixed when resizing, unless AspectRatio is Full. The value of

ImageSize can also be Tiny, Small, Medium, or Large.



7.2.2 Plot Range

** PlotRange Ranges for x and y in the plot; examples of values:

Automatic



p



c



{ymin, Automatic}



{Full, Automatic}



{ymin, All}



{{xmin, xmax}, All}



Full



{All, ymax}



{Full, {ymin, Automatic}}



5



{ymin, ymax}



{{xmin, xmax}, {ymin, ymax}}



All



g



When showing a plot, Mathematica normally displays all values of the function in the given interval.

However, if the function takes on very small or very large values on a small interval, Mathematica may

decide to cut such values away from the plot so that the remaining parts of the function can be seen

more clearly; this may happen if the value Automatic is used for PlotRange.

To see the whole function, use the value All. The value Full also causes the whole function to be

plotted but, in addition, the whole plotting range on x axis is included in the plot. A constant value such

as 5 means, for Plot, the plot range {Full, {-5, 5}} and, for Graphics and ParametricPlot, the plot

range {{-5, 5}, {-5, 5}}.

GraphicsRow@8Plot@Exp@xD, 8x, -1, 10
Plot@Exp@xD, 8x, -1, 10<, PlotRange Ø AllD, Plot@Sqrt@xD, 8x, -1, 1
Plot@Sqrt@xD, 8x, -1, 1<, PlotRange Ø AllD<, ImageSize Ø 420D

8000



1.0

0.8

0.6

0.4

0.2



20 000



6000



15 000



4000



10 000



2000



5000

0



2



4



6



8



10



2



4



6



8



10



-1.0 -0.5



0.0



1.0

0.8

0.6

0.4

0.2

0.5



1.0



0.2 0.4 0.6 0.8 1.0



In the first plot, we use the default value {Full, Automatic} of PlotRange for Plot. The y range

definition Automatic has, in this example, caused the function to be shown only up to approximately

x = 9. The x range definition Full means that the whole x range H0, 10L is shown. In the second example,

the value All is used to show the whole function up to x = 10.

In the third plot, we again use the default value {Full, Automatic}. Thus, the whole x plotting

range is included, although the function is not defined on @-1, 0L. In the fourth plot, we use the value

All, and then all the points where the function is defined (and only these points) are shown.

The ClippingStyle option can be used to define the style for how the clipped parts are displayed;

see Section 7.4.1, p. 203.

(PlotRangeClipping (Ÿ6) Whether graphics objects should be clipped at the edge of the region

defined by PlotRange or should be allowed to extend to the selection rectangle; possible values:

True c p , False g )



Chapter 7 • Graphics Options



191



7.2.3 Margins and Background

PlotRegion Specifies margins around the plot inside the selection rectangle; examples of values:

Automatic (means {{0, 1}, {0, 1}}), {{xmin, xmax}, {ymin, ymax}}

(ImageMargins Specifies margins (in printer’s points) outside the selection rectangle; examples of

values: 0, Automatic, 15, {{left, right}, {bottom, top}})

Background Color of the background; examples of values: None, LightGray



Each plot has a display area that can be seen by clicking the plot: A rectangle around the plot appears.

The curve normally fills this area, but with PlotRegion we can define other ways for the curve to be

placed in the display area. The plot region is given in scaled coordinates ranging from 0 to 1 in each

direction. The default setting Automatic is the same as {{0, 1}, {0, 1}}, which is the whole display

area. By specifying other values (values less than 0 and greater than 1 are allowed), we can adjust the

margins around the curve in the display area. For example, plots with gray or colored backgrounds

often look better with a somewhat reduced plot region (i.e., with larger margins). The second plot

shown here has a wider margin around the plot than the first plot. In the third plot, the margin is

outside the selection rectangle.

GraphicsRow@

8Plot@Sin@xD, 8x, 0, 2 p<, Background Ø LightGray, PlotRegion Ø AutomaticD,

Plot@Sin@xD, 8x, 0, 2 p<, Background Ø LightGray,

PlotRegion Ø 880.1, 0.9<, 80.1, 0.9<
Background Ø LightGray, ImageMargins Ø 10D<, ImageSize Ø 420D

1.0



1.0

1.0

0.5



0.5



-0.5



1



2



3



4



5



6



0.5

1 2 3 4 5 6



-0.5

-1.0



-1.0



-0.5



1



2



3



4



5



6



-1.0



(ImagePadding (Ÿ6) Extra space (in printer’s points) for objects such as thick lines and tick and axes

labels; examples of values: All, None, 15, {{left, right}, {bottom, top}})

(PlotRangePadding (Ÿ6) How much further axes etc. should extend beyond the range of coordinates specified by PlotRange; examples of values: Automatic, None, {0.2, 0.5})

The first plot below shows that usually the axes are a little extended (2% in each direction) from the

given x range and the range of y values. In the second plot, we use no padding, and in the third plot we

use unusually wide padding. No padding is used if an explicit plot range is used.



Plot@Sin@xD, 8x, 0, 2 p<, PlotRangePadding Ø ÒD & êü 8Automatic, None, 80.5, 0.2<<



:



1.0



1.0



0.5



0.5

1



2



3



4



5



6



,



0.0



1.0

0.5



,

1



2



3



4



5



6



1



-0.5



-0.5



-0.5



-1.0



-1.0



-1.0



2



3



4



5



6



>



Xem Thêm
Tải bản đầy đủ (.pdf) (1,135 trang)

×