user2260180
user2260180

Reputation: 275

Matlab Plot; one data set, two axis, date

I am trying to plot a single data set in terms of dates (x axis), I would like to add on the second (top) x axis with interval of time in days. Any suggestion?

Upvotes: 0

Views: 70

Answers (1)

NLindros
NLindros

Reputation: 1693

One way is to create another axes on top of the first, and put the xaxis location at the 'top' for that. Here is a small example.

% Some example data
d = linspace(now,now-7,7);
y = randn(size(d));

% Create first axes
ax1 = axes;
plot(d,y);
datetick(ax1, 'x', 'yy-mm-dd')

% Create second axes
ax2 = axes;
plot(d,y,'Visible', 'off'); % No need to show doubles
set(ax2, 'Position', ax1.Position, 'XAxisLocation', 'top', ...
    'Color', 'none' ,'YTick', []);
datetick(ax2, 'x', 'ddd')

enter image description here

Upvotes: 1

Related Questions