Addaxis (multiple y axis on left side)

37 次查看(过去 30 天)
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 中查找有关 Just for fun 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by