plot datetick with mmm, dd yyyy in lower right corner as in datetime axis
6 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(1 个)
BhaTTa
2024-12-3,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)]);
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Errorbars 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!