How to make a stacked area chart , where x axis is the datetime variable

I am learning how to draw graphs in Matlab.
I have a problem making stacked area chart. I would like to have on x axis the time and I have the time numbers as my first column of Y matrix, in datenum format. Like this:
Y = [730301, 1, 5, 3;
730302, 3, 2, 7;
730303,1, 5, 3;
730304,2, 6, 1];
If I exclude first column, which are my dates, I can easily plot by:
Y = [1, 5, 3; 3, 2, 7; 1, 5, 3; 2, 6, 1]; figure area(Y)
However, then x axis is not the one I need, and when I am trying to adjust it does not provide a correct view.
this works:
area(y(:,1), y(:,2:end))
However, i want my dates to be in yearly manner represented in graph and not datenum. What to do?

 Risposta accettata

Use the datetick (link) function:
Y = [730301, 1, 5, 3;
730302, 3, 2, 7;
730303,1, 5, 3;
730304,2, 6, 1];
figure(1)
area(Y(:,1), Y(:,2:end))
datetick('x', 'yyyy-mm-dd')
See the documentation on datetick for more options and formats.

Più risposte (1)

the cyclist
the cyclist il 8 Ago 2017
Modificato: the cyclist il 8 Ago 2017
It sounds like you need the datetick function.
Another possibility is to use the new-ish datetime type, if you are able to do that upstream of the code you shared.

Categorie

Community Treasure Hunt

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

Start Hunting!

Translated by