Email: helpdesk@telkomuniversity.ac.id

This Portal for internal use only!

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • IBM
  • Visual Paradigm
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Categories
  • Microsoft
    • Microsoft Apps
    • Office
    • Operating System
    • VLS
    • Developer Tools
    • Productivity Tools
    • Database
    • AI + Machine Learning
    • Middleware System
    • Learning Services
    • Analytics
    • Networking
    • Compute
    • Security
    • Internet Of Things
  • Adobe
  • Matlab
  • Google
  • Visual Paradigm
  • WordPress
    • Plugin WP
    • Themes WP
  • Opensource
  • Others
More Categories Less Categories
  • Get Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • My Account
    • Download
    • Cart
    • Checkout
    • Login
  • About Us
    • Contact
    • Forum
    • Frequently Questions
    • Privacy Policy
  • Forum
    • News
      • Category
      • News Tag

iconTicket Service Desk

  • My Download
  • Checkout
Application Package Repository Telkom University
All Categories

All Categories

  • IBM
  • Visual Paradigm
  • Adobe
  • Google
  • Matlab
  • Microsoft
    • Microsoft Apps
    • Analytics
    • AI + Machine Learning
    • Compute
    • Database
    • Developer Tools
    • Internet Of Things
    • Learning Services
    • Middleware System
    • Networking
    • Operating System
    • Productivity Tools
    • Security
    • VLS
      • Office
      • Windows
  • Opensource
  • Wordpress
    • Plugin WP
    • Themes WP
  • Others

Search

0 Wishlist

Cart

Menu
  • Home
    • Download Application Package Repository Telkom University
    • Application Package Repository Telkom University
    • Download Official License Telkom University
    • Download Installer Application Pack
    • Product Category
    • Simple Product
    • Grouped Product
    • Variable Product
    • External Product
  • All Pack
    • Microsoft
      • Operating System
      • Productivity Tools
      • Developer Tools
      • Database
      • AI + Machine Learning
      • Middleware System
      • Networking
      • Compute
      • Security
      • Analytics
      • Internet Of Things
      • Learning Services
    • Microsoft Apps
      • VLS
    • Adobe
    • Matlab
    • WordPress
      • Themes WP
      • Plugin WP
    • Google
    • Opensource
    • Others
  • My account
    • Download
    • Get Pack
    • Cart
    • Checkout
  • News
    • Category
    • News Tag
  • Forum
  • About Us
    • Privacy Policy
    • Frequently Questions
    • Contact
Home/Matlab/Using 3 “y” axes for multiple plot

Using 3 “y” axes for multiple plot

PuTI / 2025-01-29
Using 3 “y” axes for multiple plot
Matlab News

Hello,
I am working with multiple plots in MATLAB and I would like to use three different "y" axis for the different axes within a single figure. I have no problem using two "y" axes with yyaxis, I can’t include that function in my for loop (this loop reads the data from each column to be plotted from the Excel file). I read about a function called addaxis, but I don’t know how to use it.
Also, I would like the plots to have different colors for each "y" axis, since MATLAB defaults to red for Y1 and blue for Y2. Any ideas on how to achieve this?
Any suggestions would be greatly appreciated!
Best Regards!
Lucas.

clc;
clear;
nombre_excel = ‘Hoja_fuente.xlsx’;
datos = readtable (nombre_excel);
encabezados = datos.Properties.VariableNames(2:end);
encabezados = strrep(encabezados, ‘_’, ‘ ‘);
t = datetime(datos.Tiempo,’ConvertFrom’, ‘datenum’, ‘Format’, ‘HH:mm:ss’); %Si da probemas: sustituir ‘datenum’ por ‘excel’
numero_columnas=size(datos,2) – 1;
fig = figure(‘Name’,’Representación interactiva MATLAB’, ‘NumberTitle’,’off’, ‘Color’, ‘w’);
hold on;
grid on;

for i=2:numero_columnas+1
y_i = datos(:,i);
y_i = table2array(y_i);
if max(y_i) <= 100
yyaxis right
plot(t, y_i, ‘LineWidth’, 1.5, ‘DisplayName’, encabezados{i-1}, SeriesIndex = 1, marker=’.’, markersize = 1, color = ‘r’);
end
if max(y_i) > 100
yyaxis left
plot(t, y_i, ‘LineWidth’, 1.5, ‘DisplayName’, encabezados{i-1}, SeriesIndex = 1, marker=’.’, markersize = 1, color = ‘b’); %[‘Y_’ num2str(i-1)]
end
end

title(‘Gráfica Interactiva’);
legend(‘show’);
xlabel(‘Tiempo( hh:mm:ss )’, ‘FontSize’, 12);
%ylabel(encabezados, ‘Rotation’, 0, ‘Color’, ‘b’);
ax=gca;
ax.XAxis.Exponent = 0;
ax.XAxis.TickLabelFormat = ‘HH:mm:ss’;
axis tight;
ax.XAxis.SecondaryLabelFormatMode = ‘manual’;
set(gca, ‘Position’, [0.056770833333333,0.157667386609071,0.894270833333333,0.809935205183586]);
legend(‘Location’, ‘southoutside’, ‘NumColumns’, 6, ‘Orientation’, ‘horizontal’, ‘NumColumnsMode’,’manual’, ‘Interpreter’,’none’, ‘FontSize’, 8, ‘FontWeight’, ‘bold’, ‘FontName’, ‘Arial Narrow’, ‘box’, ‘on’);
set(legend, ‘IconColumnWidth’, 15, ‘Position’, [0.004678527128273,0.041036717062635,0.988802104021113,0.058815920456996]);
format long g;

This code is working but It can only plot 2 "y" axes; but if I try the addaxis in order to implement the third "y" axis, my code It´s not working:
clc;
clear;
nombre_excel = ‘Hoja_fuente.xlsx’;
datos = readtable (nombre_excel);
encabezados = datos.Properties.VariableNames(2:end);
encabezados = strrep(encabezados, ‘_’, ‘ ‘);
t = datetime(datos.Tiempo,’ConvertFrom’, ‘datenum’, ‘Format’, ‘HH:mm:ss’); %Si da probemas: sustituir ‘datenum’ por ‘excel’
numero_columnas=size(datos,2) – 1;
fig = figure(‘Name’,’Representación interactiva MATLAB DQA’, ‘NumberTitle’,’off’, ‘Color’, ‘w’); %Preguntar si NumberTitle on o off
hold on;
grid on;
for i=2:numero_columnas+1
y_i = datos(:,i);
y_i = table2array(y_i);
if max(y_i) <= 20
addaxis(t, y_i, [0 20],’LineWidth’,1.3,’Color’,’b’)
plot(t, y_i, ‘LineWidth’, 1.5, ‘DisplayName’, encabezados{i-1}, ‘SeriesIndex’, 1, ‘Marker’, ‘.’, ‘MarkerSize’, 1, ‘Color’, ‘green’);
end
if 20 < max(y_i) && max(y_i) <= 100
addaxis(t, y_i, [0 100], ‘LineWidth’,1.3,’Color’,’r’)
plot(t, y_i, ‘LineWidth’, 1.5, ‘DisplayName’, encabezados{i-1}, SeriesIndex = 1, marker=’.’, markersize = 1, color = ‘red’); %[‘Y_’ num2str(i-1)]
end
if max(y_i) > 100
addaxis(t, y_i, [0 max(y_i)],’LineWidth’,1.3,’Color’,’g’)
plot(t, y_i, ‘LineWidth’, 1.5, ‘DisplayName’, encabezados{i-1}, SeriesIndex = 1, marker=’.’, markersize = 1, color = ‘b’); %[‘Y_’ num2str(i-1)]
end
end
title(‘Gráfica Interactiva DiagnóstiQA’);
legend(‘show’);
xlabel(‘Tiempo( hh:mm:ss )’, ‘FontSize’, 12);
%ylabel(encabezados, ‘Rotation’, 0, ‘Color’, ‘b’);
ax=gca;
ax.XAxis.Exponent = 0;
ax.XAxis.TickLabelFormat = ‘HH:mm:ss’; %QUITAR ESTA LINEA DE CODIGO SI PREFERIMOS FORMATO TEMPORAL mm:ss
axis tight; %INSTRUCCIONES: tight, tickaligned o padded %en vez de axis puedo usar xlim o ylim si solo quiero ajustar 1 de los ejes
ax.XAxis.SecondaryLabelFormatMode = ‘manual’; %ESTO SOLUCIONA EL 31 -1!
set(gca, ‘Position’, [0.056770833333333,0.157667386609071,0.894270833333333,0.809935205183586]); %El segundo numero es el margen desde el borde inferior de la ventana y el cuarto número es la altura de los ejes
legend(‘Location’, ‘southoutside’, ‘NumColumns’, 6, ‘Orientation’, ‘horizontal’, ‘NumColumnsMode’,’manual’, ‘Interpreter’,’none’, ‘FontSize’, 8, ‘FontWeight’, ‘bold’, ‘FontName’, ‘Arial Narrow’, ‘box’, ‘on’);
set(legend, ‘IconColumnWidth’, 15, ‘Position’, [0.004678527128273,0.041036717062635,0.988802104021113,0.058815920456996]);
format long g;Hello,
I am working with multiple plots in MATLAB and I would like to use three different "y" axis for the different axes within a single figure. I have no problem using two "y" axes with yyaxis, I can’t include that function in my for loop (this loop reads the data from each column to be plotted from the Excel file). I read about a function called addaxis, but I don’t know how to use it.
Also, I would like the plots to have different colors for each "y" axis, since MATLAB defaults to red for Y1 and blue for Y2. Any ideas on how to achieve this?
Any suggestions would be greatly appreciated!
Best Regards!
Lucas.

clc;
clear;
nombre_excel = ‘Hoja_fuente.xlsx’;
datos = readtable (nombre_excel);
encabezados = datos.Properties.VariableNames(2:end);
encabezados = strrep(encabezados, ‘_’, ‘ ‘);
t = datetime(datos.Tiempo,’ConvertFrom’, ‘datenum’, ‘Format’, ‘HH:mm:ss’); %Si da probemas: sustituir ‘datenum’ por ‘excel’
numero_columnas=size(datos,2) – 1;
fig = figure(‘Name’,’Representación interactiva MATLAB’, ‘NumberTitle’,’off’, ‘Color’, ‘w’);
hold on;
grid on;

for i=2:numero_columnas+1
y_i = datos(:,i);
y_i = table2array(y_i);
if max(y_i) <= 100
yyaxis right
plot(t, y_i, ‘LineWidth’, 1.5, ‘DisplayName’, encabezados{i-1}, SeriesIndex = 1, marker=’.’, markersize = 1, color = ‘r’);
end
if max(y_i) > 100
yyaxis left
plot(t, y_i, ‘LineWidth’, 1.5, ‘DisplayName’, encabezados{i-1}, SeriesIndex = 1, marker=’.’, markersize = 1, color = ‘b’); %[‘Y_’ num2str(i-1)]
end
end

title(‘Gráfica Interactiva’);
legend(‘show’);
xlabel(‘Tiempo( hh:mm:ss )’, ‘FontSize’, 12);
%ylabel(encabezados, ‘Rotation’, 0, ‘Color’, ‘b’);
ax=gca;
ax.XAxis.Exponent = 0;
ax.XAxis.TickLabelFormat = ‘HH:mm:ss’;
axis tight;
ax.XAxis.SecondaryLabelFormatMode = ‘manual’;
set(gca, ‘Position’, [0.056770833333333,0.157667386609071,0.894270833333333,0.809935205183586]);
legend(‘Location’, ‘southoutside’, ‘NumColumns’, 6, ‘Orientation’, ‘horizontal’, ‘NumColumnsMode’,’manual’, ‘Interpreter’,’none’, ‘FontSize’, 8, ‘FontWeight’, ‘bold’, ‘FontName’, ‘Arial Narrow’, ‘box’, ‘on’);
set(legend, ‘IconColumnWidth’, 15, ‘Position’, [0.004678527128273,0.041036717062635,0.988802104021113,0.058815920456996]);
format long g;

This code is working but It can only plot 2 "y" axes; but if I try the addaxis in order to implement the third "y" axis, my code It´s not working:
clc;
clear;
nombre_excel = ‘Hoja_fuente.xlsx’;
datos = readtable (nombre_excel);
encabezados = datos.Properties.VariableNames(2:end);
encabezados = strrep(encabezados, ‘_’, ‘ ‘);
t = datetime(datos.Tiempo,’ConvertFrom’, ‘datenum’, ‘Format’, ‘HH:mm:ss’); %Si da probemas: sustituir ‘datenum’ por ‘excel’
numero_columnas=size(datos,2) – 1;
fig = figure(‘Name’,’Representación interactiva MATLAB DQA’, ‘NumberTitle’,’off’, ‘Color’, ‘w’); %Preguntar si NumberTitle on o off
hold on;
grid on;
for i=2:numero_columnas+1
y_i = datos(:,i);
y_i = table2array(y_i);
if max(y_i) <= 20
addaxis(t, y_i, [0 20],’LineWidth’,1.3,’Color’,’b’)
plot(t, y_i, ‘LineWidth’, 1.5, ‘DisplayName’, encabezados{i-1}, ‘SeriesIndex’, 1, ‘Marker’, ‘.’, ‘MarkerSize’, 1, ‘Color’, ‘green’);
end
if 20 < max(y_i) && max(y_i) <= 100
addaxis(t, y_i, [0 100], ‘LineWidth’,1.3,’Color’,’r’)
plot(t, y_i, ‘LineWidth’, 1.5, ‘DisplayName’, encabezados{i-1}, SeriesIndex = 1, marker=’.’, markersize = 1, color = ‘red’); %[‘Y_’ num2str(i-1)]
end
if max(y_i) > 100
addaxis(t, y_i, [0 max(y_i)],’LineWidth’,1.3,’Color’,’g’)
plot(t, y_i, ‘LineWidth’, 1.5, ‘DisplayName’, encabezados{i-1}, SeriesIndex = 1, marker=’.’, markersize = 1, color = ‘b’); %[‘Y_’ num2str(i-1)]
end
end
title(‘Gráfica Interactiva DiagnóstiQA’);
legend(‘show’);
xlabel(‘Tiempo( hh:mm:ss )’, ‘FontSize’, 12);
%ylabel(encabezados, ‘Rotation’, 0, ‘Color’, ‘b’);
ax=gca;
ax.XAxis.Exponent = 0;
ax.XAxis.TickLabelFormat = ‘HH:mm:ss’; %QUITAR ESTA LINEA DE CODIGO SI PREFERIMOS FORMATO TEMPORAL mm:ss
axis tight; %INSTRUCCIONES: tight, tickaligned o padded %en vez de axis puedo usar xlim o ylim si solo quiero ajustar 1 de los ejes
ax.XAxis.SecondaryLabelFormatMode = ‘manual’; %ESTO SOLUCIONA EL 31 -1!
set(gca, ‘Position’, [0.056770833333333,0.157667386609071,0.894270833333333,0.809935205183586]); %El segundo numero es el margen desde el borde inferior de la ventana y el cuarto número es la altura de los ejes
legend(‘Location’, ‘southoutside’, ‘NumColumns’, 6, ‘Orientation’, ‘horizontal’, ‘NumColumnsMode’,’manual’, ‘Interpreter’,’none’, ‘FontSize’, 8, ‘FontWeight’, ‘bold’, ‘FontName’, ‘Arial Narrow’, ‘box’, ‘on’);
set(legend, ‘IconColumnWidth’, 15, ‘Position’, [0.004678527128273,0.041036717062635,0.988802104021113,0.058815920456996]);
format long g; Hello,
I am working with multiple plots in MATLAB and I would like to use three different "y" axis for the different axes within a single figure. I have no problem using two "y" axes with yyaxis, I can’t include that function in my for loop (this loop reads the data from each column to be plotted from the Excel file). I read about a function called addaxis, but I don’t know how to use it.
Also, I would like the plots to have different colors for each "y" axis, since MATLAB defaults to red for Y1 and blue for Y2. Any ideas on how to achieve this?
Any suggestions would be greatly appreciated!
Best Regards!
Lucas.

clc;
clear;
nombre_excel = ‘Hoja_fuente.xlsx’;
datos = readtable (nombre_excel);
encabezados = datos.Properties.VariableNames(2:end);
encabezados = strrep(encabezados, ‘_’, ‘ ‘);
t = datetime(datos.Tiempo,’ConvertFrom’, ‘datenum’, ‘Format’, ‘HH:mm:ss’); %Si da probemas: sustituir ‘datenum’ por ‘excel’
numero_columnas=size(datos,2) – 1;
fig = figure(‘Name’,’Representación interactiva MATLAB’, ‘NumberTitle’,’off’, ‘Color’, ‘w’);
hold on;
grid on;

for i=2:numero_columnas+1
y_i = datos(:,i);
y_i = table2array(y_i);
if max(y_i) <= 100
yyaxis right
plot(t, y_i, ‘LineWidth’, 1.5, ‘DisplayName’, encabezados{i-1}, SeriesIndex = 1, marker=’.’, markersize = 1, color = ‘r’);
end
if max(y_i) > 100
yyaxis left
plot(t, y_i, ‘LineWidth’, 1.5, ‘DisplayName’, encabezados{i-1}, SeriesIndex = 1, marker=’.’, markersize = 1, color = ‘b’); %[‘Y_’ num2str(i-1)]
end
end

title(‘Gráfica Interactiva’);
legend(‘show’);
xlabel(‘Tiempo( hh:mm:ss )’, ‘FontSize’, 12);
%ylabel(encabezados, ‘Rotation’, 0, ‘Color’, ‘b’);
ax=gca;
ax.XAxis.Exponent = 0;
ax.XAxis.TickLabelFormat = ‘HH:mm:ss’;
axis tight;
ax.XAxis.SecondaryLabelFormatMode = ‘manual’;
set(gca, ‘Position’, [0.056770833333333,0.157667386609071,0.894270833333333,0.809935205183586]);
legend(‘Location’, ‘southoutside’, ‘NumColumns’, 6, ‘Orientation’, ‘horizontal’, ‘NumColumnsMode’,’manual’, ‘Interpreter’,’none’, ‘FontSize’, 8, ‘FontWeight’, ‘bold’, ‘FontName’, ‘Arial Narrow’, ‘box’, ‘on’);
set(legend, ‘IconColumnWidth’, 15, ‘Position’, [0.004678527128273,0.041036717062635,0.988802104021113,0.058815920456996]);
format long g;

This code is working but It can only plot 2 "y" axes; but if I try the addaxis in order to implement the third "y" axis, my code It´s not working:
clc;
clear;
nombre_excel = ‘Hoja_fuente.xlsx’;
datos = readtable (nombre_excel);
encabezados = datos.Properties.VariableNames(2:end);
encabezados = strrep(encabezados, ‘_’, ‘ ‘);
t = datetime(datos.Tiempo,’ConvertFrom’, ‘datenum’, ‘Format’, ‘HH:mm:ss’); %Si da probemas: sustituir ‘datenum’ por ‘excel’
numero_columnas=size(datos,2) – 1;
fig = figure(‘Name’,’Representación interactiva MATLAB DQA’, ‘NumberTitle’,’off’, ‘Color’, ‘w’); %Preguntar si NumberTitle on o off
hold on;
grid on;
for i=2:numero_columnas+1
y_i = datos(:,i);
y_i = table2array(y_i);
if max(y_i) <= 20
addaxis(t, y_i, [0 20],’LineWidth’,1.3,’Color’,’b’)
plot(t, y_i, ‘LineWidth’, 1.5, ‘DisplayName’, encabezados{i-1}, ‘SeriesIndex’, 1, ‘Marker’, ‘.’, ‘MarkerSize’, 1, ‘Color’, ‘green’);
end
if 20 < max(y_i) && max(y_i) <= 100
addaxis(t, y_i, [0 100], ‘LineWidth’,1.3,’Color’,’r’)
plot(t, y_i, ‘LineWidth’, 1.5, ‘DisplayName’, encabezados{i-1}, SeriesIndex = 1, marker=’.’, markersize = 1, color = ‘red’); %[‘Y_’ num2str(i-1)]
end
if max(y_i) > 100
addaxis(t, y_i, [0 max(y_i)],’LineWidth’,1.3,’Color’,’g’)
plot(t, y_i, ‘LineWidth’, 1.5, ‘DisplayName’, encabezados{i-1}, SeriesIndex = 1, marker=’.’, markersize = 1, color = ‘b’); %[‘Y_’ num2str(i-1)]
end
end
title(‘Gráfica Interactiva DiagnóstiQA’);
legend(‘show’);
xlabel(‘Tiempo( hh:mm:ss )’, ‘FontSize’, 12);
%ylabel(encabezados, ‘Rotation’, 0, ‘Color’, ‘b’);
ax=gca;
ax.XAxis.Exponent = 0;
ax.XAxis.TickLabelFormat = ‘HH:mm:ss’; %QUITAR ESTA LINEA DE CODIGO SI PREFERIMOS FORMATO TEMPORAL mm:ss
axis tight; %INSTRUCCIONES: tight, tickaligned o padded %en vez de axis puedo usar xlim o ylim si solo quiero ajustar 1 de los ejes
ax.XAxis.SecondaryLabelFormatMode = ‘manual’; %ESTO SOLUCIONA EL 31 -1!
set(gca, ‘Position’, [0.056770833333333,0.157667386609071,0.894270833333333,0.809935205183586]); %El segundo numero es el margen desde el borde inferior de la ventana y el cuarto número es la altura de los ejes
legend(‘Location’, ‘southoutside’, ‘NumColumns’, 6, ‘Orientation’, ‘horizontal’, ‘NumColumnsMode’,’manual’, ‘Interpreter’,’none’, ‘FontSize’, 8, ‘FontWeight’, ‘bold’, ‘FontName’, ‘Arial Narrow’, ‘box’, ‘on’);
set(legend, ‘IconColumnWidth’, 15, ‘Position’, [0.004678527128273,0.041036717062635,0.988802104021113,0.058815920456996]);
format long g; plot, label MATLAB Answers — New Questions

​

Tags: matlab

Share this!

Related posts

test one two three four
2025-05-20

test one two three four

Is it possible to make this tiny loop faster?
2025-05-19

Is it possible to make this tiny loop faster?

Solar Wind Battery Hybrid Integration
2025-05-19

Solar Wind Battery Hybrid Integration

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Search

Categories

  • Matlab
  • Microsoft
  • News
  • Other
Application Package Repository Telkom University

Tags

matlab microsoft opensources
Application Package Download License

Application Package Download License

Adobe
Google for Education
IBM
Matlab
Microsoft
Wordpress
Visual Paradigm
Opensource

Sign Up For Newsletters

Be the First to Know. Sign up for newsletter today

Application Package Repository Telkom University

Portal Application Package Repository Telkom University, for internal use only, empower civitas academica in study and research.

Information

  • Telkom University
  • About Us
  • Contact
  • Forum Discussion
  • FAQ
  • Helpdesk Ticket

Contact Us

  • Ask: Any question please read FAQ
  • Mail: helpdesk@telkomuniversity.ac.id
  • Call: +62 823-1994-9941
  • WA: +62 823-1994-9943
  • Site: Gedung Panambulai. Jl. Telekomunikasi

Copyright © Telkom University. All Rights Reserved. ch

  • FAQ
  • Privacy Policy
  • Term

This Application Package for internal Telkom University only (students and employee). Chiers... Dismiss