Reverse order of X axis
Show older comments
Hi everybody, I'm trying to plot the price of an option against time to expiration time in days (in positive integer ofc). But I need to reverse the time. More specifically, I have 15 daily prices so what I did was building a vector from 0 to 15 and use flipr to reverse the order of my raw vector but it doesn't work because also the price of the option was reversed.
Exp = [0:15]; %days to expiration
P = rand(1,15); %fake daily prices
plot(Exp,P) %is all reversed not just the days to expiration
I also tried with set Xdir as follows
Exp = [0:15]; %days to expiration
P = rand(1,15); %fake daily prices
plot(Exp,P)
set(gca, 'Xdir', 'reverse') %again is all reversed not just the days to expiration
Does anyone have a solution to this issue?
Thanks a lot in advace,
Best,
Marco.
9 Comments
Let's say that P started at 10 for Exp of 0 and increased to 30 for Exp=15. What would you like the data and x axis tick marks to look like?
Exp = 0:15; % Days to expiration
P = linspace(10, 30, length(Exp)); % Fake daily prices increasing
plot(Exp,P, 'b.-')
% set(gca, 'Xdir', 'reverse') %again is all reversed not just the days to expiration
Marco Piazza
on 23 Jun 2022
Edited: Marco Piazza
on 23 Jun 2022
Image Analyst
on 23 Jun 2022
OK, so the 15 would be at the left and 0 at the right. But the Exp that goes with 15 is 30. So do you want that at the left too? If you just reverse the tickmarks, then the value of Exp at the "0" tickmark will be the value of Exp that is associated with 15.
Marco Piazza
on 23 Jun 2022
Edited: Marco Piazza
on 23 Jun 2022
Image Analyst
on 23 Jun 2022
I'm still confused, as that would be confusing and not match up with the data.
Please give some monotonic data that shows price and days to expiration. Not random numbers, but something like I did. So Exp is days to expiration, and the P vector is the price at the corresponding element. Like for element 1, price is 100 and Exp is 0, for element #2 price is 110 and Exp is 4 days, or whatever. I think having the random numbers in there is making it difficult to see what's being plotted and whether it's flipped left-to-right or not.
Jan
on 23 Jun 2022
@Marco Piazza: This is not twitter. We do not use # before the tags.
Exp = 0:15; % Days to expiration
P = linspace(10, 30, length(Exp)); % Fake daily prices increasing
y=plot(Exp,P, 'b.-');
ax=xticklabels;
xticklabels(flip(ax))
Marco Piazza
on 24 Jun 2022
Edited: Marco Piazza
on 24 Jun 2022
Accepted Answer
More Answers (0)
Categories
Find more on Creating and Concatenating Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




