How to plot 3 y axis?

26 ビュー (過去 30 日間)
SOMNATH MAHATO
SOMNATH MAHATO 2021 年 11 月 13 日
編集済み: TADA 2021 年 11 月 13 日
x = [1 6 10 15 22];
y1 = [2 6 8 10 15];
y2 = [99 97 94 92 89];
y3= [1 3 6 8 11];
  1 件のコメント
TADA
TADA 2021 年 11 月 13 日
Do you mean three lines, or three axes with different units?

サインインしてコメントする。

回答 (1 件)

Cris LaPierre
Cris LaPierre 2021 年 11 月 13 日
I would probably plot this way.
x = [1 6 10 15 22];
y1 = [2 6 8 10 15];
y2 = [99 97 94 92 89];
y3= [1 3 6 8 11];
plot(x,[y1;y2;y3]')
Given the different scale of y2, I might also do it using yyaxis
figure
yyaxis left
plot(x,[y1;y3]')
yyaxis right
plot(x,y2)
The apostrophe transposes the row vectors into column vectors. MATLAB treats columns as data series, so if I have one x vector and multiple y variables, it's a way to plot them all in a single command.
  2 件のコメント
Cris LaPierre
Cris LaPierre 2021 年 11 月 13 日
編集済み: Cris LaPierre 2021 年 11 月 13 日
If you in fact want 3 separate y axes, see this answer.
TADA
TADA 2021 年 11 月 13 日
編集済み: TADA 2021 年 11 月 13 日
I would prefer to keep everything on a single axis, unless these are actually different measures (like mass and height, or whatever). If you keep everything on a single axis, you can more easily compare values, slopes, etc.
The different sizes can then be managed by either a logarithmic scale (not the best option here) or a broken axis ( https://www.mathworks.com/matlabcentral/fileexchange/21864-breakplot ), which is the best option for displaying these data in my opinion.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by