强制y轴从0开始,并且仍使用自动标签
我有一个y min的图,其最低速度远高于0。但是我想将0作为y轴的最小值,但仍然具有stata 自动创建均值均匀的y轴标签。
这是基线:
sysuse auto2, clear
scatter turn displacement
这几乎是我想要的,除了y范围不是从0开始。
基于nick Cox的答案( https://www.statalist.org/forums/forums/forums/forums/通用 - 史塔省/常规/1598753-force-chart-y轴 - 轴 - 启动 - at-0 ),我修改代码为:
scatter turn displacement, yscale(range(0 .)) ylabel(0)
这成功在0处启动y轴,但是除了0之外,标签消失了:
我继续删除`ylabel(0):
scatter turn displacement, yscale(range(0 .))
这会产生相反的问题 - y轴标签与第一个图中相同。
如何使Stata从0到最大产生Y轴标签?例如,0、10、20、30、40、50-重要的是,我有很多图,并且需要一个自动确定确切值的解决方案,而无需我输入y max等。我选择10、20,...,50,但Stata。
I have a plot whose y min starts well above 0. But I want to include 0 as the min of the y-axis and still have Stata automatically create evenly-spaced y-axis labels.
Here is the baseline:
sysuse auto2, clear
scatter turn displacement
This is almost what I want, except that the y range does not start at 0.
Based on this answer by Nick Cox (https://www.statalist.org/forums/forum/general-stata-discussion/general/1598753-force-chart-y-axis-to-start-at-0), I modify the code to be:
scatter turn displacement, yscale(range(0 .)) ylabel(0)
This succeeds in starting the y-axis at 0, but the labeling besides 0 goes away:
I proceed to remove `ylabel(0):
scatter turn displacement, yscale(range(0 .))
This produces the opposite problem - the y-axis labels are the same as in the first plot.
How can I have Stata automatically produce the y-axis labels from 0 to the max? For instance, 0, 10, 20, 30, 40, 50 - importantly, though, I have many plots and need a solution that determines the exact values automatically, without needing me to input the y max, etc. So it would not be me who chooses 10, 20, ..., 50, but Stata.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
巧合的是,我一直在这个领土上掌握指挥。这是一个可再现的例子。
其中
Nicelabels
目前为此代码。编辑
如果您去,
您会得到很好的解决方案。显然,在这种情况下,我们需要知道10或20是要使用的步骤。使用您自己的食谱将有良好的宽度来计算良好的宽度。
编辑1022年5月10日,
已修订和记录的
Nicelabels
现在可以从SSC下载。编辑2 28 2023年9月28日,现在可以访问 /em>纸。
By coincidence, I have been working on a command in this territory. Here is a reproducible example.
where
nicelabels
is at present this code.EDIT
If you go
you get good solutions. Clearly in this case we need to know that 10 or 20 is a step size to use. There would be scope to calculate a good width programmatically using your own recipe.
EDIT 10 May 2022
A revised and documented
nicelabels
is now downloadable from SSC.EDIT 2 28 Sept 2023 A write-up is now accessible in this Stata Journal paper.
尼克的解决方案更好,但是粗糙,简单的解决方案是绘制另一个在0或接近0的系列,并且可能是看不见的。例如:
但是需要注意传奇。
Nick's solution is better, but a crude and simple solution is to plot another series that is at or near 0, and it could be invisible. For example:
But care would need to be taken of the legend.