Addaxis (multiple y axis on left side)

45 visualizaciones (últimos 30 días)
Kashif Naukhez
Kashif Naukhez el 24 de Jun. de 2023
Respondida: Kashif Naukhez el 24 de Jun. de 2023
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.

Respuestas (3)

Shivam
Shivam el 24 de Jun. de 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 -

Image Analyst
Image Analyst el 24 de Jun. de 2023

Kashif Naukhez
Kashif Naukhez el 24 de Jun. de 2023
here is the reference

Categorías

Más información sobre Just for fun en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by