How to change the decimal separator of abbreviated axes ticks?

31 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

Renee Coetsee
Renee Coetsee il 24 Mar 2017
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.
  1 Commento
Peter J
Peter J il 28 Mar 2017
This workaround surely doesn't loose the powers of ten, and it might be ok for my current needs. It also expands every number to two decimal places (even if those are zero). This clutters the labels a bit, but it's probably acceptable for my customers. Thank you for your response.

Accedi per commentare.

Più risposte (0)

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by