Changing the values on an axis in Matlab 2014b
3 views (last 30 days)
Show older comments
Attila Lazar
on 11 Oct 2014
Commented: Oleg Komarov
on 12 Oct 2014
I have recently installed Matlab 2014b and some of my earlier graph formatting code does not work anymore. I have several graphs in programmatic gui and when I have a large number to plot, e.g. 15000, the program automatically displays it on the y-axis as 1.14x10^4. I would like to display the y-axis values as 11400 or 11,400. This code used to work with Matlab 2014a:
ax1=handles.fig_results;
plot(x1m, y1, x1m, y2, 'parent', ax1);
hleg1 = legend('Male population','Female population', 'Location','SouthWest');
xlabel('years', 'FontSize',12,'FontWeight','bold','parent', ax1);
ylabel('No of individuals', 'FontSize',14,'FontWeight','bold','parent', ax1);
yt = get(ax1,'YTick'); % change the tickmark format
set(ax1,'YTickLabel', sprintf('%.0f|',yt));
When I run this code in Matlab 2014b, now, all the y-tick values are the same: 11000|11100|11200|11300|11400
Is there a way to fix this? Thanks!
0 Comments
Accepted Answer
Geoff Hayes
on 11 Oct 2014
Attila - looking at the documentation for changing tick labels of graph, the YTickLabel (and XTickLabel) can (should?) be set with a cell array of strings. (In the past, I would have done something similar to you and just passed a string.)
So try converting your string of numbers into a cell array. Since you are suffixing each number with the pipe character, then you should be able to do the following
set(ax1,'YTickLabel', strsplit(sprintf('%.0f|',yt),'|'));
Here we are using strsplit to split the string at the | delimiter.
1 Comment
More Answers (0)
See Also
Categories
Find more on Axis Labels in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!