Datetick将情节中的NaN考虑在内 [英] Datetick take into account NaN in plot

查看:69
本文介绍了Datetick将情节中的NaN考虑在内的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含值的系列y,其中一些是NaN一些数字(双精度).

I have a series y that contains values, some of which are NaN some numeric (double).

该系列有一个关联的向量d,其中包含datenum个日期.

The series has an associated vector d which contains the datenum dates.

示例:

y=[NaN(5,1); rand(10,1)]
d=now-14:now

当我跑步时:

plot(d,y)

我得到了想要的图形; NaN观测值被取出.

I get the graph I want; the NaN observations are taken out.

但是,当我跑步时:

plot(d,y); datetick

然后我的图从头开始,并考虑了所有观察结果(即使yNaN时).

then my graph starts from the beginning and takes into account all the observations (even when y is a NaN).

如何防止这种情况发生?

How can I prevent this from happening?

推荐答案

来自文档中,我们可以看到有一种简单的方法(如下所示)来保留当前的轴限制.

From the documentation we can see that there is an easy way (shown below) to preserve the current axes limits.

plot(d,y);
datetick('keeplimits');

'keeplimits'参数完全按照其建议执行操作,在将刻度值转换为日期的同时保持x轴限制.您可能还希望通过'keepticks'来保留刻度线的位置.

The 'keeplimits' argument does exactly what it suggests, maintaining the x-axis limits whilst converting the tick values to dates. You may also want to pass 'keepticks' to preserve tick mark locations.

您描述的行为似乎与文档相反:

The behaviour you describe seems contrary to the docs:

datetick根据指定轴的最小和最大限制选择标签格式.

datetick selects a label format based on the minimum and maximum limits of the specified axis.

根据该语句,我希望这些值保持不变,但是显然内部处理限制的方式有些不同,这意味着包括了NaN点.至少我们得到了一个简单的解决方法!

From this statement I would expect the values to remain the same, but there is obviously something about the way the limits are handled internally which means the NaN points are included. At least we are given a simple work around!

这篇关于Datetick将情节中的NaN考虑在内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆