changing the axis of a plot in a way that the data series starts at x=0 at a point at one point on the y-axis and ends on the right end of the plot

3 ビュー (過去 30 日間)
hi,
I have this code:
dates=datenum(VIXdate)
y=VIX
plot(dates,y)
%datevc divides the date in different columns, first colum is the year,
%second the month and thrid the day
d=datevec(dates)
%Takes just the year (first column)
d=d(:,1)
%takes every year just once
[a,idx]=unique(d(:,1),'first')
ylabel('VIX');
set(gca,'xtick',dates(idx),'xticklabel',a)
set(gca,'Box','off')
this works fine, but the problem I faces is that the time series (y=VIX) does not start at the left end of the plot but instead there is a space between the y-axis and the first point of the time series. I know that when there are normal values on the x-axis, I can change it, but I am not able to do it with dates, what do I need to do?

採用された回答

Jonathan Epperl
Jonathan Epperl 2013 年 5 月 2 日
This is still not a working example, the variable VIXdate is obviously unknown to us...
So the dirty way again:
ytix = get(gca,'YTick');
set(gca,'YTick',ytix(2:end));
  3 件のコメント
Jonathan Epperl
Jonathan Epperl 2013 年 5 月 2 日
You should make that a new question, and finally make it so that we can copy and paste your code into our matlab and run it and see what it is you want to achieve.
Locks
Locks 2013 年 5 月 2 日
編集済み: Locks 2013 年 5 月 2 日
ok, I did so, it's fine now, thanks

サインインしてコメントする。

その他の回答 (2 件)

Mel
Mel 2013 年 5 月 1 日
You could also set just the x axis to be the same as your data:
xlim([0 max(dates)])

Jonathan Epperl
Jonathan Epperl 2013 年 4 月 29 日
  3 件のコメント
Jonathan Epperl
Jonathan Epperl 2013 年 5 月 1 日
Sure. Without knowing what your actual data looks like (it would still be nice if you could post a working minimal example), you could do that:
ylims = get(gca,'YLim');
axis tight
set(gca,'YLim',ylims);
Dirty, but should work.
Locks
Locks 2013 年 5 月 1 日
編集済み: Locks 2013 年 5 月 1 日
dates=datenum(VIXdate)
y=VIX
plot(dates,y)
d=datevec(dates)
%Takes just the year (first column)
d=d(:,1)
%takes every year just once
[a,idx]=unique(d(:,1),'first')
ylabel('VIX');
set(gca,'xtick',dates(idx),'xticklabel',a)
ylims = get(gca,'YLim');
axis tight
set(gca,'YLim',ylims);
set(gca,'Box','off')
it's working perfectly now, thanks!
in addition, it would be great if the number 0 on the y axis is not shown in the plot due to the fact that it's so near to the numbers on the x axis, is there a way to do that?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeAnnotations についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by