Setting additional specific axis tick marks
显示 更早的评论
I have a y axis that spans 0 - 15. I want to place an extra tick mark (labelled with its value) at the minimum value of y (0.018 in one data set, for example).
It is not appropriate for me to use a log scale - the data is well presented, it is just not obvious to the reader that the minimum value is not zero.
Thank you.
采纳的回答
set(gca, 'YTick', sort([0.018, get(gca, 'YTick')]));
9 个评论
Thank you Walter. Now the 0.018 value is sitting on top of the '0' label of the y axis so both values are hard to read. Is it possible to remove the default'0' value so that the axis starts 0.018 then continues as specified by default? In this example the other labels on the graph (specified by default) are 5, 10 , 15 - I'd like to be able to generalize to other graphs too.
ytick = get(gca, 'YTick');
ytick(1) = 0.018;
set(gca, 'YTick', ytick);
Alternative in one line:
set(gca, 'YTick', max(0.018, get(gca, 'YTick')));
Thank you Walter.
This is awesome
Erik Lundgren
2017-12-23
编辑:Erik Lundgren
2017-12-23
set(gca, 'YTick', max(0.018, get(gca, 'YTick'))); <-- Wonderful! Thanks Walter!
set(gca, 'YTick', unique([0.018, get(gca, 'YTick')]));
Using unique instead of sort prevents an error is the added tick was already there
How can the label be added in similar fasion?
After setting the YTick, you can pull out the YTick again and format the values and send those to the YTickLabels property.
With R2014b or later you would typically only do that if you had special formatting needs, such as needing one label to look different than the others, or if you wanted to convert each value to its multiple of Pi : for plain formatting issues you would instead set the axes YAxis.TickLabelFormat property.
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Grid Lines, Tick Values, and Labels 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
