📄 axis_label_options.hlp
字号:
The options documented
below will allow you to change each attribute of a tick and its label, but
the {it:tickstyle} specifies the starting point.
{p 8 8 2}
You need not specify {cmd:tstyle()} just because there is something
you want to change about the look of ticks or labels. You specify
{cmd:tstyle()} when another style exists that is exactly what you desire
or when another style would allow you to specify fewer changes to obtain
what you want.
{phang}
{opth labgap(relativesize)},
{opth labstyle(textstyle)},
{opth labsize(textsizestyle)}, and
{opth labcolor(colorstyle)}
specify details about how the labels are presented.
{phang}
{cmd:tlength(}{it:relativesize}{cmd:)}
specifies the overall length of the ticks.
{phang}
{cmd:tposition(outside}|{cmd:crossing}|{cmd:inside)}
specifies whether the ticks are to extend {cmd:outside} (from the axis
out, the usual default), {cmd:crossing} (crossing the axis
line, extending in and out), or {cmd:inside} (from the axis
into the plot region).
{phang}
{opth tlstyle(linestyle)},
{opth tlwidth(linewidthstyle)},
{opth tlcolor(colorstyle)},
{opth tlpattern(linepatternstyle)}
specify other details about the look of the ticks.
Ticks are just lines.
See {help lines} for more information.
{phang}
{cmd:grid} and {cmd:nogrid}
specify whether grid lines are to be drawn across the plot region in
addition to whatever else is specified in the
{c -(}{cmd:y}|{cmd:x}{c )-}[{cmd:m}]{cmd:label()} or
{c -(}{cmd:y}|{cmd:x}{c )-}[{cmd:m}]{cmd:tick()}
option in which {cmd:grid} or {cmd:nogrid} appears.
Typically, {cmd:nogrid} is
the default, and {cmd:grid} is the option for all except
{cmd:ylabel()}, where things are reversed and {cmd:grid} is the default
and {cmd:nogrid} is the option. (Which is the default and which is the
option is controlled by the scheme; see {help schemes}.)
{p 8 8 2}
For instance, specifying option
{cmd:ylabel(, nogrid)}
{p 8 8 2}
would suppress the grid lines in the {it:y} direction and specifying
{cmd:xlabel(, grid)}
{p 8 8 2}
would add them in the {it:x}. Specifying
{cmd:xlabel(0(1)10, grid)}
{p 8 8 2}
would place major labels, major ticks,
and grid lines at {it:x} = 0, 1, 2, ..., 10.
{phang}
[{cmd:no}]{cmd:gmin} and
[{cmd:no}]{cmd:gmax}
are relevant only if {cmd:grid} is in effect (because {cmd:grid} is
the default and {cmd:nogrid} was not specified or because {cmd:grid}
was specified).
[{cmd:no}]{cmd:gmin} and
[{cmd:no}]{cmd:gmax}
specify whether grid lines are to be drawn at the minimum and maximum
values. Consider
{p 12 16 2}
{cmd:. scatter yvar xvar, xlabel(0(1)10, grid)}
{p 8 8 2}
Clearly the values 0, 1, ..., 10 are to be ticked and labeled, and clearly,
grid lines should be drawn at 1, 2, ..., 9; but should grid lines be drawn
at 0 and 10? If 0 and 10 are at the edge of the plot region, you probably
do not want grid lines there. They will be too close to the axis
and border of the graph.
{p 8 8 2}
What you want will differ from graph to graph, so the {cmd:graph} command
tries to be smart, meaning that
neither {cmd:gmin} nor {cmd:nogmin} (and neither {cmd:gmax} nor
{cmd:nogmax}) are the defaults: The default is for {cmd:graph} to decide
which looks best; the options force the decision one way or the other.
{p 8 8 2}
If {cmd:graph} decided to suppress the grids at the extremes and
you wanted them, you could type
{p 12 16 2}
{cmd:. scatter yvar xvar, xlabel(0(1)10, grid gmin gmax)}
{phang}
{cmd:gstyle(}{it:gridstyle}{cmd:)}
specifies the overall style of the grid lines, including whether the lines
extend beyond the plot region and into the plot region's margins,
along with the style, color, width, and pattern of the lines themselves.
The options that follow allow you to change each attribute, but the
{it:gridstyle} provides the starting point.
{p 8 8 2}
You need not specify {cmd:gstyle()} just because there is something
you want to change. You specify {cmd:gstyle()} when another style
exists that is exactly what you desire or when another style would allow
you to specify fewer changes to obtain what you want.
{phang}
{cmd:gextend} and {cmd:nogextend}
specify whether the grid lines should extend beyond the plot region
and pass through the plot region's
margins; see {it:{help region_options}}. The default is determined
by the {cmd:gstyle()} and scheme, but in most cases, {cmd:nogextend}
is the default and {cmd:gextend} is the option.
{phang}
{opth glstyle(linestyle)},
{opth glwidth(linewidthstyle)},
{opth glcolor(colorstyle)},
{opth glpattern(linepatternstyle)}
specify other details about the look of the grid.
Grids are just lines.
See {help lines} for more information.
Of these options, {cmd:glpattern()} is of particular interest
because, with it, you can make the grid lines dashed.
{title:Remarks}
{pstd}
{it:axis_label_options} are a subset of {it:axis_options};
see {it:{help axis_options}} for an overview.
The other appearance options are
{it:axis_scale_options}{right:(see {it:{help axis_scale_options}}) }
{it:axis_title_options}{right:(see {it:{help axis_title_options}}) }
{pstd}
Remarks are presented under the headings
{help axis_label_options##remarks1:Default labeling and ticking}
{help axis_label_options##remarks2:Controlling the labeling and ticking}
{help axis_label_options##remarks3:Adding extra ticks}
{help axis_label_options##remarks4:Adding minor labels and ticks}
{help axis_label_options##remarks5:Adding grid lines}
{help axis_label_options##remarks6:Suppressing grid lines}
{help axis_label_options##remarks7:Substituting text for labels}
{help axis_label_options##appendix:Appendix: Details of syntax}
{help axis_label_options##appendix1:Suboptions without rules, numlists, or labels}
{help axis_label_options##appendix2:Rules}
{help axis_label_options##appendix3:Rules and numlists}
{help axis_label_options##appendix4:Rules and numlists and labels}
{help axis_label_options##appendix5:Interpretation of repeated options}
{marker remarks1}{...}
{title:Default labeling and ticking}
{pstd}
By default, approximately five values are labeled and ticked on each axis.
For example, in
{cmd:. sysuse auto, clear}
{cmd:. scatter mpg weight}
{it:({stata "gr_example auto: scatter mpg weight":click to run})}
{* graph mpgweight}{...}
{pstd}
four values are labeled on each axis because choosing five would have required
widening the scale too much.
{marker remarks2}{...}
{title:Controlling the labeling and ticking}
{pstd}
We would obtain the same results as we did in the above example if we typed,
{phang2}
{cmd:. scatter mpg weight, ylabel(#5) xlabel(#5)}
{pstd}
Options {cmd:ylabel()} and {cmd:xlabel()} specify the values to be labeled and
ticked, and {cmd:#5} specifies that Stata choose approximately five values for
us. If we wanted lots of values labeled, we might type
{phang2}
{cmd:. scatter mpg weight, ylabel(#10) xlabel(#10)}
{p_end}
{it:({stata "gr_example auto: scatter mpg weight, ylabel(#10) xlabel(#10)":click to run})}
{* graph axislab2}{...}
{pstd}
As with {cmd:#5}, {cmd:#10} was not taken too seriously; we obtained 7 labels
on the {it:y} axis and 8 on the {it:x} axis.
{pstd}
Alternatively, we can specify precisely the values we want labeled by
specifying {it:#}{cmd:(}{it:#}{cmd:)}{it:#} or by specifying
a list of numbers:
{cmd:. scatter mpg weight, ylabel(10(5)45)}
{cmd: xlabel(1500 2000 3000 4000 4500 5000)}
{it:({stata "gr_example auto: scatter mpg weight, ylabel(10(5)45) xlabel(1500 2000 3000 4000 4500 5000)":click to run})}
{* graph axislab3}{...}
{pstd}
In option {cmd:ylabel()}, we specified the rule {cmd:10(5)45}, which means
to label 10 to 45 in steps of 5. In option {cmd:xlabel()}, we typed out the
values to be labeled.
{marker remarks3}{...}
{title:Adding extra ticks}
{pstd}
Options {cmd:ylabel()} and {cmd:xlabel()} draw ticks plus labels.
Options {cmd:ytick()} and {cmd:xtick()} draw ticks only, so you can do things
like
{cmd:. scatter mpg weight, ytick(#10) xtick(#15)}
{it:({stata "gr_example auto: scatter mpg weight, ytick(#10) xtick(#15)":click to run})}
{* graph axislab4}{...}
{pstd}
Of course, as with {cmd:ylabel()} and {cmd:xlabel()}, you can specify the
exact values you want ticked.
{marker remarks4}{...}
{title:Adding minor labels and ticks}
{pstd}
Minor ticks and minor labels are smaller than regular ticks and regular
labels. Options {cmd:ymlabel()} and {cmd:xmlabel()} allow you to place
minor ticks with labels, and {cmd:ymtick()} and {cmd:xmtick()} allow you to
place minor ticks without labels. When using minor ticks and labels,
in addition to the usual syntax of {cmd:#5} to mean approximately 5 values,
{cmd:10(5)45} to mean 10 to 45 in steps of 5, and a list of numbers, there is
an additional syntax: {cmd:##5}. {cmd:##5} means 5-1=4 minor ticks or labels
between the major ticks. Why {cmd:##5} means 4 and not 5 we will explain
momentarily.
{pstd}
The graph below is intended more for demonstration than an example of a
good-looking graph:
{phang2}
{cmd:. scatter mpg weight, ymlabel(##5) xmtick(##10)}
{p_end}
{it:({stata "gr_example auto: scatter mpg weight, ymlabel(##5) xmtick(##10)":click to run})}
{* graph axislab5}{...}
{pstd}
{cmd:##5} means 4 ticks and {cmd:##10} means 9 ticks because most people think
in reciprocals: They say to themselves, "I want to tick the fourths so I want
4 ticks between," or, "I want to tick the tenths so I want 10 ticks between".
They think incorrectly. They should think that if they want fourths, they
want 4-1=3 ticks between, or if they want tenths, they want 10-1=9 ticks
between. Stata subtracts one so that they can think{hline 2}and
correctly{hline 2}when they want fourths that they want {cmd:##4} ticks
between and that when they want tenths they want {cmd:##10} ticks between.
{marker remarks5}{...}
{title:Adding grid lines}
{pstd}
To obtain grid lines, specify the {cmd:grid} suboption of {cmd:ylabel()},
{cmd:xlabel()}, {cmd:ymlabel()}, or {cmd:xmlabel()}. {cmd:grid} specifies
that, in addition to whatever else the option would normally do, grid lines
be drawn at the same values. Note that in the example below,
{cmd:. sysuse uslifeexp, clear}
{cmd:. line le year, xlabel(,grid)}
{it:({stata "gr_example uslifeexp: line le year, xlabel(,grid)":click to run})}
{* graph axislab6}{...}
{pstd}
we specify {cmd:xlabel(,grid)}, omitting any mention of the specific values to
use. Thus {cmd:xlabel()} did what it does ordinarily (labeled approximately
5 nice values), and it drew grid lines at those same values.
{pstd}
Of course, we
could have specified the values to be labeled and gridded:
{cmd:. line le year, xlabel(#10, grid)}
{cmd:. line le year, xlabel(1900(10)2000, grid)}
{phang2}
{cmd:. line le year, xlabel(1900 1918 1940(20)2000, grid)}
{pstd}
The {cmd:grid} suboption is usually specified with {cmd:xlabel()}
(and with {cmd:ylabel()} if, given the scheme, {cmd:grid} is not the
default),
but it may be specified with any of the
{it:axis_label_options}.
In the example below, we "borrow"
{cmd:ymtick()} and {cmd:xmtick()}, specify {cmd:grid} to make them draw
grids, and also specify {cmd:style(none)} to make the ticks themselves
invisible:
{cmd:. sysuse auto, clear}
{cmd:. scatter mpg weight, ymtick(#20, grid tstyle(none))}
{cmd: xmtick(#20, grid tstyle(none))}
{it:({stata "gr_example auto: scatter mpg weight, ymtick(#20, grid tstyle(none)) xmtick(#20, grid tstyle(none))":click to run})}
{* graph axislab7}{...}
{pstd}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -