简体   繁体   中英

Matlab: Financial time series plot xTickLable bug?

I think this might be a bug. I am using 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.

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. If you type get(gca, 'yTickMode') , you will get auto . If you type get(gca, 'xTickMode') , you will get 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') . Afterwards, what you get is a messed up xTickLable. It's not a hard-to-read problem that could be solved by rotation of the 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(datetime(datestr(dates)),Data)
xtickformat('dd-MMM-yyyy');
legend('PERMIT')
grid on

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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