How to change the decimal separator of abbreviated axes ticks?
9 ビュー (過去 30 日間)
古いコメントを表示
I am trying to format an axes with a non-US number convention (because i have to). That is: i need a comma as decimal separator in my ticklabels, not a dot. My current take on this is:
allaxes = findall(0, 'type', 'axes');
for ii = 1:size(allaxes,1)
allaxes(ii).XTickLabels = char(allaxes(ii).XTickLabels);
allaxes(ii).YTickLabels = char(allaxes(ii).YTickLabels);
for jj = 1:size(allaxes(ii).XTickLabels,1)
allaxes(ii).XTickLabels(allaxes(ii).XTickLabels == '.') = ',';
allaxes(ii).YTickLabels(allaxes(ii).YTickLabels == '.') = ',';
end
end
But that only works satisfactory for short numbers, i.e. numbers that are not automatically reformated with a 10^3 or the like. If i use the above script, it just drops the power of 10, rendering the whole label useless. And as i'm producing A LOT of diagrams a manual retouch of every diagram is a serious waste of my time.
So does anyone have an idea on this? Or is there a way of notifying Mathworks, that this is utterly annoying for a large part of the world? (see here: https://en.wikipedia.org/wiki/Decimal_mark#Countries_using_Arabic_numerals_with_decimal_point )
By the way, there is another annoyance with the above method: the char() function adds spaces to all numbers, which are shorter than the longest one. This moves around the ticklabels, so they often stray off their respective ticks.
0 件のコメント
採用された回答
Renee Coetsee
2017 年 3 月 24 日
I work in MathWorks Technical Support, and the developers have been notified of your feature request. They will consider adding this capability in a future MATLAB release. Thank you for the feedback!
Please see the following example for a workaround:
plot(0.1:0.1:10000);
ha = gca;
lx = addlistener(ha,'XLim','PostSet',@fcn);
ly = addlistener(ha,'YLim','PostSet',@fcn);
fcn(ha);
function fcn(ha)
str = get(ha,'YTick'); %get the ytick values
str = arrayfun(@(x) {strrep(sprintf('%.2f',x),'.',',')}, str); %replaces . with ,
set(ha,'YTickLabel',str);
end
Please open a technical support case if this does not fix the issue.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Axis Labels についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!