I need to plot precipitation data. First, adjust y limits of a stacked plot to accommodate totals for the month. Second, have dates on the x axis.

조회 수: 1 (최근 30일)
I have a working script (see below), however, I'm not familiar with setting ylimits of a stacked plot since it's the only plot function that seems to work for me. I would also like to take column one data and plot it on the x axis. Precipitation must be in hundreths of units.
close all;
clear all;
clc;
tbl = readtable('March_Precipitation');
P = tbl(:,2);
s = stackedplot(P)
S.LineWidth = 2;

채택된 답변

Cris LaPierre
Cris LaPierre 2024년 4월 12일
What do you want your YLims to be?
As for dates, if your X data is a datetime, then your x axis will display dates.
tbl = readtable('March_Precip.xlsx','TextType','string');
tbl.Properties.VariableNames = ["Date","Precipitation"];
tbl.Precipitation = double(tbl.Precipitation);
plot(tbl, 'Date','Precipitation')
  댓글 수: 3
Cris LaPierre
Cris LaPierre 2024년 4월 12일
Is there something about a stackedplot that you cannot achieve with a regular plot? Otherwise, just use a regular plot and ylims as you normally would.
I've updated the plot command to use the plot(x,y) syntax instead.
tbl = readtable('March_Precip.xlsx','TextType','string');
tbl.Properties.VariableNames = ["Date","Precipitation"];
tbl.Precipitation = double(tbl.Precipitation);
plot(tbl.Date,tbl.Precipitation)
ylim([3 5])
Jonathon Klepatzki
Jonathon Klepatzki 2024년 4월 12일
Na, I tried to use a regular plot before I posted this and it didn't work. The error specifically said to use stacked as a suggestion. I appreciate your help!

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

추가 답변 (1개)

Star Strider
Star Strider 2024년 4월 12일
Convert the table to a timetablee and ‘Column2’ will automatically be plotted as a funciton of the time variable.
However I don’t understand ‘Precipitation must be in hundreths of units.’. It can be transformed easily enough by multiplying ‘Column2’ by a constant. The y-tick values (or labels) can also be transformed as easily. What changes need to be made?
Try this —
F = openfig('Precip.fig');
F.Visible = 1;
T1 = readtable('March_Precip.xlsx');
T1.Column2 = str2double(T1.Column2);
TT1 = table2timetable(T1)
TT1 = 2978x1 timetable
Column1 Column2 ____________________ _______ 01-Mar-2024 00:00:00 3.222 01-Mar-2024 00:15:00 3.222 01-Mar-2024 00:30:00 3.222 01-Mar-2024 00:45:00 3.222 01-Mar-2024 01:00:00 3.222 01-Mar-2024 01:15:00 3.222 01-Mar-2024 01:30:00 3.221 01-Mar-2024 01:45:00 3.222 01-Mar-2024 02:00:00 3.222 01-Mar-2024 02:15:00 3.222 01-Mar-2024 02:30:00 3.222 01-Mar-2024 02:45:00 3.222 01-Mar-2024 03:00:00 3.222 01-Mar-2024 03:15:00 3.222 01-Mar-2024 03:30:00 3.222 01-Mar-2024 03:45:00 3.222
figure
stackedplot(TT1)
.
  댓글 수: 3
Cris LaPierre
Cris LaPierre 2024년 4월 13일
For a timetable, I suggest reading the Excel file using readtimetable
TT = readtimetable('March_Precip.xlsx','TextType','string');
TT.Properties.VariableNames = ["Precipitation"];
TT.Precipitation = str2double(TT.Precipitation);
stackedplot(TT)
ylim is not supported for stackedplot, but there is a workaround. See this Answer.

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

카테고리

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

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by