empty space between values when making bar chat with datetime

2 views (last 30 days)
I'm trying to make a stacked bar chat with some value on the y-axis and time on x-axis using datetime.
An example of my data:
2008-Jan-14 15:00:00 0 69 1154 1444.8
2008-Mar-01 13:00:00 0 69 1098 1375.8
2008-Jun-24 15:00:00 0 70 105 399.3
2008-Aug-30 12:00:00 0 68 168 710.5
2008-Sep-14 19:00:00 338 69 638 1614.3
2008-Dec-11 20:00:00 525 69 100 1000.3
The problem is, because of the many days between my values, there is a huge gap in my plot and I can barely even see the bars. So is there a way to remove the negative space while still using datetime on my x-axis?
Thanks in advance.

Answers (1)

Eric Sofen
Eric Sofen on 26 Jun 2020
That's a tough one. Obviously, if you were doing a standard x-y plot, you'd want the datetime axis to realistically represent time. Similarly, if you are doing a bar chart with fairly densely/uniformly spaced data.
In this case, perhaps the best bet is to plot against 1:numel(dates) and then update the axis labels with text representations of the timestamps:
t = datetime+calmonths([0 3 4 5 11 12]);
data = rand(size(t));
bar(1:numel(t),data)
xticklabels(string(t))

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!