I have created a time series plot. My x axis shows the dates that correspond with each point as intended, however, it is only showing four dates. For this particular data file, there are 17 dates. Is there a way to change the way the date values show up?

 채택된 답변

dpb
dpb 2018년 8월 15일

0 개 추천

You can set the tick locations and formatting as desired; you'll may have to rotate to get enough room for as much as you're wanting to show to be legible; dates/times take up a lot of real estate.

댓글 수: 2

Thanks, that definitely helped. I would now like to put equal spacing between each tick mark, however, there is no function to specify the spacing on that page. How can I do it?
text = struct2cell(text)';
Dates = text(:,1);
GAUGE_ts = timeseries(RNFLG,Dates);
SAT_ts = timeseries(SAT_RNFL,Dates);
plot(GAUGE_ts)
hold on
plot(SAT_ts)
ax = gca;
ax.XAxis.TickValues = datetime(Dates);
ax.XAxis.TickLabelFormat = 'M/d';
ax.XAxis.TickLabelRotation = 45;
ax.XAxis.FontSize = 8.5;
Well, approximately log-distributed times on a datetime axes seems a little unusual...bet nobody at TMW ever thought of somebody having data that looked like that! :)
What you need to do is to set the XTick values to a set across the axes limits instead of using every observed value -- ticks and data points don't have to coincide.
Try something like (air code, don't have your data to play with but should work I believe)
xtk=xlim; % retrieve default axes limits
Ntk=10; % pick a number of ticks desired
ax.XTick=linspace(xtk(1),xtk(2),Ntk);
Salt to suit.
I not used the timeseries object enough to know and the doc was pretty obtuse; does it store the times as explicit field or is buried in the properties and in your creation as above are the values of
GAUGE_ts.Time
datetimes equiavelent to Dates? I'm presuming that's so in which case you could eliminate creating the other variable as a minor efficiency.
If you want the axes limits different, just do the same thing as above to set the axis limits; and then set the ticks to match.
It does seem as though a useful enhancement would be to be able to specify number of major ticks as well rather than requiring the tick values...

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Line Plots에 대해 자세히 알아보기

질문:

2018년 8월 15일

댓글:

dpb
2018년 8월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by