![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1418478/image.png)
Addaxis (multiple y axis on left side)
42 views (last 30 days)
Show older comments
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.
0 Comments
Answers (3)
Shivam
on 24 Jun 2023
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 -
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1418478/image.png)
0 Comments
See Also
Categories
Find more on Subplots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!