Could you tell me how can I change an axis "multiplier"? I mean a value I circled in the picture, let's say I would like to have x10^3 instead of x10^4.
Matlab - change axis multiplier
Asked Answered
You can use the following Matlab Central tick2text: create easy-to-customize tick labels
along with the sprintf
formatting.
As of R2015b it is part of the Numeric Ruler Properties:
ax = get(gca);
ax.YAxis.Exponent = -3;
I have little bit tricky solution:
- Set
YTickMode
tomanual
. - Set your own
YTickLabel
. - Place the text on top with your desired multiplier.
here is:
set(gca, 'YTickMode', 'manual');
set(gca, 'YTickLabel', get(gca,'YTick') / 1000);
text(0, 1.02 * get(gca,'YLim')(2), 'x 10^3');
Play with the multiplier 1.02
in the third line to place your text to the good place.
You didn't understand my question. I don't want to change axis limits, but values on the axis. In my example, I need to have values 0,10,20,...,100 with x10^3 multiplier instead of 0,1,2,...,10 with x10^4 multiplier on my y-axis –
Daubigny
Sorry, I thoght
num2str
of an array will create new array with strings, not the string line. I also noticed, that num2str was redundant. Try now. –
Bantling Ok, it works like a charm now with an one exception. I had to change
text(0, 1.02 * get(gca,'YLim')(2), 'x 10^3');
to tmp = get(gca,'YLim'); text(0, 1.02 * tmp(2), 'x 10^3');
. Perhaps my version doesn't accept your type of index expression. Anyway, that's an acceptable answer as well. Thank you! –
Daubigny I would use
'{\times}10^3'
for text
. –
Cultrate You can use the following Matlab Central tick2text: create easy-to-customize tick labels
along with the sprintf
formatting.
It seems the fastest way from all of the answers. Here is the code if somebody would has a problem
tick2text(gca,'yformat', @(x) sprintf('%2u', x/10^9)
Thx @Macduff. –
Daubigny Scale your data by 0.1, which gives you the multiplier you want.
Then override the tick labels so that tick 1.0 is labelled 10, etc.
But overriding the tick labels removes the multiplier, doesn't it? –
Morpheus
@Luis: I saw some plots where it didn't, but they might have done something exotic. –
Forrer
© 2022 - 2024 — McMap. All rights reserved.
tick2text(gca,'yformat', @(x) sprintf('%2u', x/10^9)
Thx @Macduff. – Daubigny