Date stamp on plot

조회 수: 3 (최근 30일)
Brian Gregory
Brian Gregory 2021년 6월 10일
편집: Star Strider 2021년 6월 10일
Hello.
I am having an issue where I am plotting data using datetime (converting from excel) and it is giving me the date stamp of the current day on the plot. I need to specify the date I want and stamp it onto the plots without interfering with the data. How can I do this?
Thanks!
  댓글 수: 2
Scott MacKenzie
Scott MacKenzie 2021년 6월 10일
So, you are reading a date and time from Excel into a datetime variable, but the datetime variable is for the current day not the day in the Excel file. It might help if you provide the data and your code.
Brian Gregory
Brian Gregory 2021년 6월 10일
Hi Scott. That is exactly right except the data conversion only has the time, not the date. I am unable to provide the data due to confidentiality reasons, but here is a graph that has the date. This is by no means the data I am trying to plot but it is a plot of the time from the datetime conversion with the date at the top. That is the date I would like to change.

댓글을 달려면 로그인하십시오.

채택된 답변

Star Strider
Star Strider 2021년 6월 10일
편집: Star Strider 2021년 6월 10일
The only way I can devise to delete the date is to create new y-tick labels and use them instead —
F = openfig('untitled.fig');
Ax = gca; % Axis Handle
yt = Ax.YTick; % Y-Tick Values
ythm = compose("%02d:%02d", [hour(yt); minute(yt)].') % Create New Ones
Ax.YTickLabel = ythm; % Use Them For The New Y-Ticks
text(min(xlim), max(ylim), 'Your Date Here', 'Vert','bottom', 'Horiz','left')
The new plot —
EDIT — (10 Jun 2021 at 16:46)
Added text call to insert ‘Your Date Here’ date information.
.

추가 답변 (1개)

Steven Lord
Steven Lord 2021년 6월 10일
plot(1:10, 1:10)
title("This plot was created at " + string(datetime('now')))

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by