plot datetick with mmm, dd yyyy in lower right corner as in datetime axis

6 visualizzazioni (ultimi 30 giorni)
Hi,
I am creating an errorbar plot using datetick to to display time (hh:MM) in my datenum x-axis, and would like to display the date (eg mmm, dd yyyy) ONLY ONCE in the lower right corner, like it is automatically done when I create a plot with a datetime axis (which isn't possible with errobar). Does somebody know how to do this?

Risposte (1)

BhaTTa
BhaTTa il 3 Dic 2024 alle 4:05
Hey @F S, I understand that you want to display a date label in the lower right corner of a plot with a datenum x-axis, you can manually add a text annotation to your plot. This approach will allow you to display the date in the format "mmm, dd yyyy" only once in the specified location.
Please refer to below code:
% Sample data
dates = datenum('2023-09-01'):datenum('2023-09-30');
values = randn(size(dates));
errors = rand(size(dates)) * 0.5;
% Create the errorbar plot
figure;
errorbar(dates, values, errors, 'o-');
datetick('x', 'HH:MM', 'keepticks'); % Use 'HH:MM' for time on x-axis
grid on;
% Get the last date in the range
lastDate = dates(end);
% Format the date as 'mmm, dd yyyy'
formattedDate = datestr(lastDate, 'mmm, dd yyyy');
% Add the date label to the lower right corner
% Adjust the position as needed
text('String', formattedDate, ...
'Units', 'normalized', ...
'Position', [0.95, 0.05], ... % Adjust position (x, y) as needed
'HorizontalAlignment', 'right', ...
'VerticalAlignment', 'bottom', ...
'FontSize', 10);
% Set axis limits to ensure the text is visible
xlim([dates(1), dates(end)]);
ylim([min(values - errors), max(values + errors)]);

Categorie

Scopri di più su Errorbars in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by