フィルターのクリア

How do I set YAxis of Axes from a numeric ruler to a datetime ruler?

15 ビュー (過去 30 日間)
Victor Esparza
Victor Esparza 2019 年 1 月 7 日
コメント済み: Adam Danz 2021 年 2 月 11 日
I would like to dynamically set the Yaxis to a datetime ruler.
Example Code:
figure;
aa=axes;
set(aa,'YAxis', matlab.graphics.axis.decorator.DatetimeRuler);
I get the following error:
Error
Error using matlab.graphics.axis.Axes/set
You cannot set the read-only property 'YAxis' of Axes.
I was able to set the xaxis to a datetime ruler but, the yaxis is set as read-only for some reason.
  3 件のコメント
dpb
dpb 2019 年 1 月 7 日
I'm guessing this is a non-supported feature that TMW expects that if you want a datetimeruler axis that you'll create the axis with such. Doc for the axes object implies such.
Seems like there could be a time and place to be able to do this programmatically, I'd agree...submit enhancement request.
nanren888
nanren888 2019 年 1 月 7 日
Will datetick() do?
I know, just another numeric ruler, but it does some things.

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

採用された回答

Cris LaPierre
Cris LaPierre 2019 年 1 月 7 日
This can be handled automatically if your Y variable is a datetime.
td = datetime(datestr(now + [0:10]'),'Format','MMM-dd');
x = 0:10;
plot(x,td)
yDateTime.png
  6 件のコメント
Eric Delgado
Eric Delgado 2021 年 2 月 11 日
Unfortunately it is not possible to change the ruler of an axes. It is a read only property. The simplest and natural solution is just put a new data under the old data.
fig = figure;
ax = axes(fig);
data1 = line(ax, 1:10, linspace(datetime([2020 12 01]), datetime([2020 12 10]), 10))
ax.YAxis
% You have a datetime ruler axes.
cla
data1 = line(ax, 1:10, 1:10)
ax.YAxis
% And now you have a numerical ruler axes.
Adam Danz
Adam Danz 2021 年 2 月 11 日
> Unfortunately it is not possible to change the ruler of an axes
Yes it is, in at least some contexts. Cris and I both share methods directly above.
To clarify your solution, cla() is the only reason it works. When you clear the axis, it's a blank slate and the axes will respond to the data classes again. If you remove cla from your answer, it no longer works. But it's a good point. Clearing the axis is a solution. But it doesn't really convert the axes. It just resets them.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Properties についてさらに検索

製品


リリース

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by