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?

 Réponse acceptée

dpb
dpb le 15 Août 2018

0 votes

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 commentaires

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;
dpb
dpb le 15 Août 2018
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...

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Line Plots dans Centre d'aide et File Exchange

Question posée :

le 15 Août 2018

Commenté :

dpb
le 15 Août 2018

Community Treasure Hunt

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

Start Hunting!

Translated by