Changing scientific notation on plot
7 次查看(过去 30 天)
显示 更早的评论
Hello, I'm having issues changing the default scientific notation used on some plots I'm making. I've tried the following lines of code. yt=get(ax(2), 'ytick');
set(ax(2), 'YTickLabel',sprintf('%.0d',yt));
When I use these lines, it plots every tick value for that axis, at every tick on that axis. Does anyone know what I'm doing wrong? I can't seem to figure it out. Attached is an image of the plot after the above two lines of code are executed.
<<
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/149318/image.png)
>>
Thanks for your time
0 个评论
采纳的回答
更多回答(2 个)
Stephen23
2015-4-22
编辑:Stephen23
2015-4-22
The output of sprintf is a simple string, so MATLAB repeats this string for each tick mark. If you want to define each string uniquely, then supply them in a cell array. The axes properties documentation states this clearly: "Tick mark labels, specified as a cell array of strings. If you do not specify enough strings for all the ticks marks, then the axes cycles through the specified strings"
If yt is a numeric vector (which it should be!), then this will convert those values to a cell array of strings:
arrayfun(@(n)sprintf('%.0d',n), yt, 'UniformOutput',false)
0 个评论
hongyu zhai
2016-2-19
编辑:Stephen23
2016-2-19
There is a simple way to change the Axis scientific notation by change the basic property of the XAxis or YAxis.
These two example will help you.
1 个评论
Mike Garrity
2016-2-19
We should note that this is a feature that was introduced in R2015b. It is a lot nicer than messing around with the TickLabels by hand as seen above, but you won't be able to use it with earlier versions of MATLAB.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Two y-axis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!