简体   繁体   English

Matlab:金融时间序列图xTickLable错误?

[英]Matlab: Financial time series plot xTickLable bug?

I think this might be a bug. 我认为这可能是一个错误。 I am using Matlab 2015a. 我正在使用Matlab 2015a。 After I created a fints (financial time series) object, when I tried to plot it, the xTickLabel would not update when I zoomed in. If I set the xTickMode to Auto , then it would mess up itself. 创建fints(金融时间序列)对象后,当我尝试对其进行绘制时,放大时xTickLabel不会更新。如果将xTickMode设置为Auto ,则它将自身弄乱。

I did this. 我做到了 You can simply do the same and see what happens: 您可以简单地做同样的事情,看看会发生什么:

% Create financial time series:
url_1 = fred('https://research.stlouisfed.org/fred2/');
FredData = fetch(url_1, 'PERMIT');
dates = FredData.Data(:,1);
Data = FredData.Data(:,2);    
fts = fints(dates, Data , 'PERMIT');
close(url_1);

%% Plot
F1 = figure;
h1 = plot (fts.PERMIT);

Here if you zoom in, then the yTickLabel will update but not the xTickLabel. 如果您在此处放大,则yTickLabel将更新,但xTickLabel不会更新。 If you type get(gca, 'yTickMode') , you will get auto . 如果键入get(gca, 'yTickMode') ,则将获得auto If you type get(gca, 'xTickMode') , you will get manual . 如果键入get(gca, 'xTickMode') ,则将获得manual

Now the problem comes. 现在问题来了。 If you try to fix the lack of automatic update problem of the xTickLable, you will natually type set(gca, 'xTickMode', 'auto') . 如果您尝试解决xTickLable缺少自动更新的问题,则将自然键入set(gca, 'xTickMode', 'auto') Afterwards, what you get is a messed up xTickLable. 然后,您得到的是一个混乱的xTickLable。 It's not a hard-to-read problem that could be solved by rotation of the xTickLabel. 通过旋转xTickLabel可以解决这不是一个很难理解的问题。 The time itself will get messed up, so that you no longer know at which time the data were registered when you look at the chart. 时间本身会很混乱,因此当您查看图表时,您不再知道何时注册数据。 You can try it yourself, and then you will see what I mean. 您可以自己尝试,然后您会明白我的意思。

My question is, how to fix this or bypass this problem. 我的问题是,如何解决此问题或绕过此问题。

Thanks! 谢谢!

You can workaround this by using the plot in with its common syntax and then set the x-tick-label format: 您可以通过使用带有常见语法的plot来解决此问题,然后设置x-tick-label格式:

plot(datetime(datestr(dates)),Data)
xtickformat('dd-MMM-yyyy');
legend('PERMIT')
grid on

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM