Matlab - change axis multiplier
Asked Answered
D

4

5

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.

enter image description here

Daubigny answered 24/11, 2013 at 21:10 Comment(0)
H
1

You can use the following Matlab Central tick2text: create easy-to-customize tick labels

http://www.mathworks.com/matlabcentral/fileexchange/16003-tick2text-create-easy-to-customize-tick-labels

along with the sprintf formatting.

Horsepower answered 24/11, 2013 at 21:34 Comment(1)
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
L
5

As of R2015b it is part of the Numeric Ruler Properties:

ax = get(gca);
ax.YAxis.Exponent = -3;
Lice answered 11/5, 2016 at 20:20 Comment(0)
B
3

I have little bit tricky solution:

  1. Set YTickMode to manual.
  2. Set your own YTickLabel.
  3. 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.

Bantling answered 24/11, 2013 at 21:42 Comment(4)
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-axisDaubigny
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
H
1

You can use the following Matlab Central tick2text: create easy-to-customize tick labels

http://www.mathworks.com/matlabcentral/fileexchange/16003-tick2text-create-easy-to-customize-tick-labels

along with the sprintf formatting.

Horsepower answered 24/11, 2013 at 21:34 Comment(1)
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
F
1

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.

Forrer answered 24/11, 2013 at 22:6 Comment(2)
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.