Saving as .fig changes dateticks and grid spacing
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
SvB
am 6 Dez. 2016
Kommentiert: Peter Perkins
am 11 Dez. 2016
I have two sets of data providing temperature information for a specific day.
Exporting the resulting figure as a .png works fine, but exporting as .fig (File -> Save As) and re-opening that file causes visual changes along the x-axis. (Matlab R2015a)
My code:
% Read first dataset
% [SNIP]
% Manually enter day
time_days = input('What day? \n');
% Plot first line
figure(1)
plot(time1,Tair)
xlabel('Date & Time')
ylabel('T_{air} (°C)')
title('Air temperature')
grid on
% Import second dataset
% [SNIP]
% Plot second line
figure(1)
hold on
plot(time2,T_airRR)
xlim(datenum([dateshift(time2(1),'start','month')+days(time_days-1)+hours(6)-minutes(1) dateshift(time2(1),'start','month')+days(time_days)-hours(2)+minutes(1)]))
legend('Ship','Base')
The second dataset covers the entire month even though I plot only one day of the data, hence the xlim construction. It jumps back to the beginning of the month, then forward to the correct day, and then adds/subtracts hours so that the data shown is from 05:59 to 22:01. time1 and time2 are both datetime arrays.
Running this yields the LEFT figure. Saving as .fig and re-opening yields the RIGHT figure.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/158718/image.png)
Clearly, the x-axis is broken, because the data cursor still provides correct values. Also, panning or zooming in resets the axis, 'fixing' it.
What's going on here, how can I prevent it?
2 Kommentare
DrewVam55
am 6 Dez. 2016
I am not exactly sure what is happening here, but I would suggest looking at http://www.mathworks.com/matlabcentral/fileexchange/27075-intelligent-dynamic-date-ticks for help with date/time axes.
David Barry
am 7 Dez. 2016
Bearbeitet: David Barry
am 7 Dez. 2016
Certainly doesn't sound right! Can you upload some example data so we can run your example? I would also recommend contacting MathWorks technical support.
Akzeptierte Antwort
Walter Roberson
am 7 Dez. 2016
Please check out https://www.mathworks.com/support/bugreports/1246428 and see if the workaround solves your problem.
2 Kommentare
Peter Perkins
am 11 Dez. 2016
SvB, it's also worth noting that if you can upgrade to R2016b, you can set the axis limits (and similar things) with datetime values, without having to call datenum:
xlim([dateshift(time2(1),'start','month')+days(time_days-1)+hours(6)-minutes(1) dateshift(time2(1),'start','month')+days(time_days)-hours(2)+minutes(1)])
Also, when working with datetimes that don't have a timezone set, you're save using days, but if you start using timezones, you're going to want to use caldays to account for DST shifts. Using caldays even without timezones won't hurt.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Dates and Time finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!