필터 지우기
필터 지우기

Addaxis (multiple y axis on left side)

조회 수: 43 (최근 30일)
Kashif Naukhez
Kashif Naukhez 2023년 6월 24일
답변: Kashif Naukhez 2023년 6월 24일
I want to create a plot with multiple y axis on left side and only one y axis on right side. The data is attached.
I want a plot between x versus y and x versus z in left side and y versus z on right side of y axis.

답변 (3개)

Shivam
Shivam 2023년 6월 24일
Hi Kashif,
You can go through following utilities in matlab to achieve this -
- yyaxis to create chart with two y-axes - yyaxis
- subplot to create axes in tiled positions - subplot
After going through this I would suggest you to try it out first .
In case of any difficulties, you can refer to this code -
% Read data from the Excel file
filename = 'Data.xlsx';
data = xlsread(filename);
% Extract the columns from the data
x = data(:, 1);
y = data(:, 2);
z = data(:, 3);
% Create the plot with multiple y-axes
fig = figure;
ax1 = subplot(1, 2, 1); % Left subplot for x versus y and x versus z
yyaxis(ax1, 'left');
plot(x, y, 'b', 'LineWidth', 1.5);
hold on;
plot(x, z, 'r', 'LineWidth', 1.5);
ylabel(ax1, 'y and z');
xlabel(ax1, 'x');
ax2 = subplot(1, 2, 2); % Right subplot for y versus z
plot(y, z, 'g', 'LineWidth', 1.5);
ylabel(ax2, 'z');
xlabel(ax2, 'y');
grid on;
% Adjust the positions of the subplots
ax1.Position = [0.1, 0.15, 0.35, 0.7];
ax2.Position = [0.55, 0.15, 0.35, 0.7];
Result -

Image Analyst
Image Analyst 2023년 6월 24일

Kashif Naukhez
Kashif Naukhez 2023년 6월 24일
here is the reference

카테고리

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

태그

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by