Effacer les filtres
Effacer les filtres

Plotting dates as text in the x-axis

3 vues (au cours des 30 derniers jours)
Tarek Zaqout
Tarek Zaqout le 7 Juin 2019
Modifié(e) : dpb le 7 Juin 2019
Hi,
I have a timeseries in the form of '23-Feb-2019 05:00:00' and I would like to plot it them as text in the x-axis. The problem I'm having is that I want to plot them without order. Either as text or as datetime data. They're originally datetime and when I plot them, Matlab puts them in order.
Thanks.
  9 commentaires
Tarek Zaqout
Tarek Zaqout le 7 Juin 2019
I thought so. No actually they are too many. They are for a time period extending for 4 months. Hourly data.
dpb
dpb le 7 Juin 2019
Modifié(e) : dpb le 7 Juin 2019
Ouch! 4*30*24 = 2880. There's no way to even show that many distinct events on a plot--a typical monitor resolution is somethng like 1920x1080 pixels so it's about 1.5:1 events/pixel even if the line took up the entire monitor--and a typical figure display is only using a small fraction of the screen real estate.

Connectez-vous pour commenter.

Réponses (1)

dpb
dpb le 7 Juin 2019
Modifié(e) : dpb le 7 Juin 2019
To plot as ordinal position in the array instead of in order (what else could plot do with actual values on an axis with numerical or temporal variables but plot the data where it belongs?) use the one-argument form for plot as
hL=plot(Y);
We don't have enough context to know whether by "timeseries" you mean a MATLAB timeseries class or just a set of data with associated times in some other storage scheme so can't write a specific solution that know applies to your case exactly as far as syntax. Y is your data above without the time--use whatever variable name you have and what form is needed to reference it as it is stored.
Then use the 'XTickLabel' property to write the dates to the axis. Probably the best would be to start by retrieving the 'XTick' values and building a datetime array from them by interpolating/extrapolating from the input data times by position index for "pretty" intervals or set xlim([1 numel(Y)]) to match the exact number of elements in the time series to the axes, then retrive the timestamps at the 'XTick' values and write to 'XTickLabel'. Probably will have to do some additional clean up formatting once you see how much room you've got--time labels are way builkier than just numeric labels; may have room for only every other or even every 3rd or 4th...
ADDENDUM
On reflection, this seems to have a general flaw in that if that data aren't in sequential order and you label some subset of points there's no way to know what time the other points represent--as described, they could be anything?
What is the point of plotting time-specific data on some other sequential order when won't be able to identify which are associated with what time for all simply for lack of there being sufficient space to do so? What are we trying to illustrate with this particular plot--seems like some other format would likely be better for the purpose.
  2 commentaires
Tarek Zaqout
Tarek Zaqout le 7 Juin 2019
Well, I'm trying to plot the biggest rainfall events. I have ranked them from largest to smallest, and I want to plot them this way. The problem is that I can't find a way to plot them with their respective dates without plotting them in an ascending manner (e.g. Feb 1st to Feb 28th). Instead I want them to be plotted descending from highest event to lowest.
I thought if I there's a way for matlab to interpret the dates as names and plot accordingly. It seems not possible though.
dpb
dpb le 7 Juin 2019
Modifié(e) : dpb le 7 Juin 2019
The above is the way to plot in the sorted/ordinal order by ranking. It totally defies the meaning of a numerically-ordered axes for the dates to be plotted as the abscissa value and not be placed on the axis at their proper location--if that were to happen, it would break every other application of such an axis.
You could make the dates a categorical variable but by default they would be sorted so you would have to specify the associated order vector...I hadn't thought of that option when writing the above. But, see the above note regarding the number of events you're trying to show and physical limitations of display hardware.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Calendar dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by