Plot multiple variables with stackedplot with data for the x-axis?

조회 수: 26 (최근 30일)
Selim Öngüdü
Selim Öngüdü 2022년 8월 12일
댓글: dpb 2022년 8월 15일
Hi,
I am using the stackedplot function to plot multiple variables onto the same y-axis.
The code looks like this:
figure
stp = stackedplot(table,vars);
The variable table is a table where each column is one of the variables I want to plot. Vars is a cell array containing the table column names. So this code works for me, but I want the x-axis to be a time axis (I have a vector with the time values). Right now the x-axis is the number of the row in table.
How can I change the x-axis to have my time values?
Thanks
Selim

채택된 답변

Selim Öngüdü
Selim Öngüdü 2022년 8월 15일
I figured it out. The variable that you want to be the data for the x-axis, has to be a column of the table input. Than the value for "XVariable" is the number of the correct column.
  댓글 수: 1
dpb
dpb 2022년 8월 15일
"The variable that you want to be the data for the x-axis, has to be a column of the table input."
Oh. Yes. I had thought that was self-evident since the table object is the first argument.
But, the 'XVariable' argument can be specified as either the column number, name as string/cellstr/char vector, or a logical addressing vector with the appropriate true element set, it doesn't have to be just the numeric column number.

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

추가 답변 (1개)

dpb
dpb 2022년 8월 12일
From the doc, about the third input syntax description is
stackedplot(___,'XVariable',xvar)
  댓글 수: 3
dpb
dpb 2022년 8월 12일
편집: dpb 2022년 8월 12일
Well, yes, you must specify only one variable for the x axis, stackedplot doesn't handle different x,y combinations for various plots; only one x for all y.
That wouldn't be a bad enhancement, @Adam Danz if you're watching! :)
Adam Danz
Adam Danz 2022년 8월 15일
The syntax dpd recommended is for table syntax only.
'xvar' could be a string or index indicating a column in a table.
stackedplot is designed to compare multiple Ys against 1 X. If you want to use multiple X's then I recommend using nx1 tiledlayout with TileSpacing = none.
There's stackedaxes on the File Exchange, too.

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

카테고리

Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by