How to begin axis from another value and make it a 0 point in plot matlab?

212 views (last 30 days)
Hi,
I have some measurements. On the x label they starts from 0 to 100, but from 23 I can see something change on the plot, so I want to show a plot from 23 to 100, and that is how i do this:
plot(x,y)
axis(23, 100, 0, 40)
let's say that y is from 0 to 40 and i don't want to change it.
But now I want to make 23 a 0, so then the 100 whould be 77- how can I make this?
Thanks

Accepted Answer

Benjamin Kraus
Benjamin Kraus on 5 Mar 2018
If you want the ticks on your plot to show something other than the real numbers, you can either (a) change the numbers, or (b) manually specify your tick values.
To demonstrate, let me create some fake data:
x = 0:100;
fakedata = x/10;
fakedata(24:end) = sin(fakedata(24:end)-2.3)+2.3;
plot(x, fakedata)
Your two options are to either: change the X-values to something different (recommended):
plot(x-23, fakedata)
xlim([0 77])
Or manually specify your tick values:
plot(x,fakedata)
xlim([23 100]);
xticks(23:10:100);
xticklabels(0:10:77);

More Answers (3)

Jos (10584)
Jos (10584) on 5 Mar 2018
1) change the limits
plot(x,y)
xlim([23 100])
2) change the data (not recommended)
plot(x,y-23)

KSSV
KSSV on 5 Mar 2018
xlim([23 100])
Read about xlim and ylim

Magda
Magda on 5 Mar 2018
Thank You for Your response, but i meant something else
For example I made my axis from 2 to 10 because only on this range I have sth interesting, and the same plot I want to have in the range from 0 to 8 (I want cheat a little bit my measurements that the beginning of measure is somewhere else) In this example it would looks like this:
The first one is with Your recommendetion (xlim), and the second one is what I want

Tags

Community Treasure Hunt

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

Start Hunting!