📄 axis_label_options.hlp
字号:
If you look carefully at the graph above, you will find that no grid line was
drawn at {it:x}=5,000. Stata suppresses grid lines when
they get too close to the axes or borders of the graph. If you want to
force Stata to draw them anyway, you can specify the {cmd:gmin} and
{cmd:gmax} options:
{cmd:. scatter mpg weight, ymtick(#20, grid tstyle(none))}
{cmd: xmtick(#20, grid tstyle(none) gmax)}
{marker remarks6}{...}
{title:Suppressing grid lines}
{pstd}
Some commands, and option {cmd:ylabel()},
usually draw grid lines by default.
For instance, in the following, results are the same as if you specified
{cmd:ylabel(,grid)}:
{cmd:. sysuse auto, clear}
{cmd:. scatter mpg weight, by(foreign)}
{it:({stata "gr_example auto: scatter mpg weight, by(foreign)":click to run})}
{* graph mpgweightby}{...}
{pstd}
To suppress the grid lines, specify {cmd:ylabel(,nogrid)}:
{phang2}
{cmd:. scatter mpg weight, by(foreign) ylabel(,nogrid)}
{marker remarks7}{...}
{title:Substituting text for labels}
{pstd}
In addition to specifying explicitly the values to be labeled by
specifying things such as {cmd:ylabel(10(10)50)}
or {cmd:ylabel(10 20 30 40 50)},
you can specify text to be substituted for the label. If you type
{phang2}
{cmd:. graph} ...{cmd:,} ...{cmd:ylabel(10 20 30 "mean" 40 50)}
{pstd}
The values 10, 20, ..., 50 will be labeled, just as you would expect,
but for the middle value, rather than the text "30" appearing, the text
"mean" (without the quotes) would appear.
{pstd}
In the advanced example below we specify
{cmd:xlabel(1 "J" 2 "F" 3 "M" 4 "A" 5 "M" 6 "J"}
{cmd: 7 "J" 8 "A" 9 "S" 10 "O" 11 "N" 12 "D")}
{pstd}
so that rather than seeing the numbers 1, 2, ..., 12 (which are month numbers),
we see J, F, ..., D; and we specify
{phang2}
{cmd:ylabel(12321 "12,321 (mean)", axis(2) angle(0))}
{pstd}
so that we label 12321 but, rather than seeing 12321, we see "12,321 (mean)".
The {cmd:axis(2)} option puts the label on the second {it:y} axis
(see {help axis_choice_options}) and {cmd:angle(0)} makes the
text appear horizontally rather than vertically (see {hi:Options} above):
{cmd}. sysuse sp500, clear
. generate month = month(date)
. sort month
. by month: egen lo = min(volume)
. by month: egen hi = max(volume)
. format lo hi %10.0gc
. summarize volume
{txt} Variable {c |} Obs Mean Std. Dev. Min Max
{hline 13}{c +}{hline 56}
volume {c |}{res} 248 12320.68 2585.929 4103 23308.3{cmd}
. by month: keep if _n==_N
. twoway rcap lo hi month,
xlabel(1 "J" 2 "F" 3 "M" 4 "A" 5 "M" 6 "J"
7 "J" 8 "A" 9 "S" 10 "O" 11 "N" 12 "D")
xtitle("Month of 2001")
ytitle("High and Low Volume")
yaxis(1 2) ylabel(12321 "12,321 (mean)", axis(2) angle(0))
ytitle("", axis(2))
yline(12321, lstyle(foreground))
msize(*2)
title("Volume of the S&P 500", margin(b+2.5))
note("Source: Yahoo!Finance and Commodity Systems Inc."){txt}
{it:({stata "gr_example2 tworcap":click to run})}
{* graph tworcap}{...}
{marker appendix}{...}
{title:Appendix: Details of syntax}
{marker appendix1}{...}
{title:Suboptions without rules, numlists, or labels}
{pstd}
What may appear in each of the options
{c -(}{cmd:y}|{cmd:x}{c )-}{c -(}{cmd:label}|{cmd:tick}|{cmd:mlabel}|{cmd:mtick}{c )-}{cmd:()}
is a rule or numlist followed by suboptions:
{p 8 16 2}
[{it:rule}]
[{it:numlist} [{cmd:"}{it:label}{cmd:"} [{it:numlist}
[{cmd:"}{it:label}{cmd:"} [...]]]]]
[{cmd:,} {it:suboptions}]
{pstd}
Note that {it:rule}, {it:numlist}, and {it:label} are optional. Remove those,
and you are left with
{p 8 16 2}
{cmd:,} {it:suboptions}
{pstd}
That is, the options
{c -(}{cmd:y}|{cmd:x}{c )-}{c -(}{cmd:label}|{cmd:tick}|{cmd:mlabel}|{cmd:mtick}{c )-}{cmd:()}
may be specified with just suboptions and, in fact, they are often specified
that way. If you want default labeling of the {it:y} axis and {it:x} axis,
but you want grid lines in the {it:x} direction as well as the {it:y}, specify
{phang2}
{cmd:. scatter} {it:yvar} {it:xvar}{cmd:, xlabel(,grid)}
{pstd}
When you do not specify the first part{hline 2}the {it:rule}, {it:numlist}, and
{it:label}{hline 2}you are saying that you do not want that part to change. You
are saying that you merely wish to change how the {it:rule},
{it:numlist}, and {it:label} are displayed.
{pstd}
Of course, you may specify more than one suboption. You might type
{phang2}
{cmd:. scatter} {it:yvar xvar}{cmd:, xlabel(,grid format(%9.2f))}
{pstd}
if, in addition to grid lines, you wanted the numbers presented on the
{it:x} axis to be presented in a %9.2f format.
{marker appendix2}{...}
{title:Rules}
{pstd}
What may appear in each of the axis-label options is a rule or numlist
{p 8 16 2}
[{it:rule}]
[{it:numlist} [{cmd:"}{it:label}{cmd:"} [{it:numlist}
[{cmd:"}{it:label}{cmd:"} [...]]]]]
[{cmd:,} {it:suboptions}]
{pstd}
where either {it:rule} or {it:numlist} must be specified and both may be
specified. Let us ignore the {cmd:"}{it:label}{cmd:"} part right now. Then
the above simplifies to
{p 8 16 2}
[{it:rule}]
[{it:numlist}]
[{cmd:,} {it:suboptions}]
{pstd}
where {it:rule} or {it:numlist} must be specified, both may be specified,
and most often you will simply specify the {it:rule}, which may be any of the
following:
{it:rule}{col 18}example{col 30}description
{hline 70}
{cmd:#}{it:#}{...}
{col 18}{cmd:#6}{...}
{col 30}6 nice values
{cmd:##}{it:#}{...}
{col 18}{cmd:##10}{...}
{col 30}10-1=9 values between major ticks;
{col 30} allowed with {cmd:mlabel()} and {cmd:mtick()} only
{it:#}{cmd:(}{it:#}{cmd:)}{it:#}{...}
{col 18}{cmd:-4(.5)3}{...}
{col 30}specified range: -4 to 3 in steps of .5
{cmd:minmax}{...}
{col 18}{cmd:minmax}{...}
{col 30}minimum and maximum values
{cmd:none}{...}
{col 18}{cmd:none}{...}
{col 30}label no values
{cmd:.}{...}
{col 18}{cmd:.}{...}
{col 30}skip the rule
{hline 70}
{pstd}
The most commonly specified rules are {cmd:#}{it:#} and {cmd:##}{it:#}.
{pstd}
Specifying {cmd:#}{it:#} says to choose {it:#} nice values.
Specifying {cmd:#5} says to choose five nice values, {cmd:#6} means to choose
six, and so on. If you specify {cmd:ylabel(#5)}, then five values
will be labeled (on the {it:y} axis). If you also specify {cmd:ymtick(#10)},
then ten minor ticks will also be placed on the axis. Actually,
{cmd:ylabel(#5)} and {cmd:ymtick(#10)} will result in approximately five labels
and ten minor ticks because the choose-a-nice-number routine will change your
choice a little if, in its opinion, that would result in a nicer overall
result. You may not agree with the routine about what is nice, and in
that case, the {it:#}{cmd:(}{it:#}{cmd:)}{it:#} rule will let you
specify exactly what you want, assuming that you want evenly spaced
labels and numbers.
{pstd}
{cmd:##}{it:#} is allowed only with the
{c -(}{cmd:y}|{cmd:x}{c )-}{cmd:mlabel()}
and
{c -(}{cmd:y}|{cmd:x}{c )-}{cmd:mtick()} options{hline 2}the options that result
in minor ticks. {cmd:##}{it:#} says to put {it:#}-1 minor ticks between the
major ticks. {cmd:##5} would put four, and {cmd:##10} would put nine.
In this case, {it:#} is taken seriously, at least after subtraction, and you
are given exactly what you request.
{pstd}
{it:#}{cmd:(}{it:#}{cmd:)}{it:#} can be used with major or minor labels and
ticks. This rule says to label the first number specified, increment by the
second number, and keep labeling, as long as the result is less than or equal
to the last number specified. {cmd:ylabel(1(1)10)} would label (and tick) the
values 1, 2, ..., 10. {cmd:ymtick(1(.5)10)} would put minor ticks at 1, 1.5,
2, 2.5, ..., 10. It would be perfectly okay to specify both of those options.
When specifying rules, minor ticks and labels will check what is specified for
major ticks and labels and remove the intersection so as not to overprint.
The results will be the same as if you specified {cmd:ymtick(1.5(1)9.5)}.
{pstd}
The rule {cmd:minmax} specifies that you want the minimum and maximum.
{cmd:ylabel(minmax)} would label only the minimum and maximum.
{pstd}
Rule {cmd:none} means precisely that: the rule that results in no labels
and no ticks.
{pstd}
Rule {cmd:.} makes sense only when {cmd:add} is specified, although it is
allowed at other times, and then {cmd:.} means the same as {cmd:none}.
{marker appendix3}{...}
{title:Rules and numlists}
{pstd}
Following the {it:rule}{hline 2}or instead of it{hline 2}you can specify a
{it:numlist}. A numlist is a list of numbers, for instance,
"{cmd:1 2 5 7}" (without the quotes) or "{cmd:3/9}" (without the quotes).
Other shorthands are allowed (see {help numlist}), and in fact, one of
{it:numlist}'s syntaxes looks just like a {it:rule}:
{it:#}{cmd:(}{it:#}{cmd:)}{it:#}. It has the same meaning, too.
{pstd}
There is, however, a subtle distinction between, for example,
{cmd:ylabel(1(1)10)} (a {it:rule})
and
{cmd:ylabel(none 1(1)10)} (a {it:numlist})
{pstd}
{it:Rules} are more efficient.
Visually, however, there is no difference.
{pstd}
Use numlists when the values you wish to label or to tick are unequally
spaced,
{cmd:ylabel(none 1 2 5 7)}
{pstd}
or when there is one or more extra values you want to label or to tick:
{cmd:ylabel(1(1)10 3.5 7.5)}
{marker appendix4}{...}
{title:Rules and numlists and labels}
{pstd}
{it:Numlists} serve an additional purpose{hline 2}you can specify text that
is to be substituted for the value to be labeled. For instance,
{cmd:ylabel(1(1)10 3.5 "Low" 7.5 "Hi")}
{pstd}
says to label 1, 2, ..., 10 (that is the {it:rule} part) and in addition,
to label the special values 3.5 and 7.5. Rather than actually printing
"3.5" and "7.5" next to the ticks at 3.5 and 7.5, however, {cmd:graph}
will instead print the words "Low" and "Hi".
{marker appendix5}{...}
{title:Interpretation of repeated options}
{pstd}
Each of the axis-label options may be specified more than once in the same
command. If you do that and you do not specify suboption {cmd:add}, the
rightmost of each is honored. If you specify suboption {cmd:add}, then
the option just specified and the previous options are merged; see
{help repeated options}.
{title:Also see}
{psee}
Manual: {bf:[G] {it:axis_label_options}}
{psee}
Online: {it:{help axis_options}};
{it:{help axis_scale_options}},
{it:{help axis_title_options}};
{it:{help datelist}}
{p_end}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -