trying to plot multiple y axis

I am trying to plot up to 5 y Variable on the same figure using the same X axis (time) with up to 5 differetn y axis
I have been trying to use plotyy but i can only make it work for two variables.
If i add the third one i get an error that says not enough input arguments.
Can someone lend a hand?

3 Kommentare

Adam Danz
Adam Danz am 13 Aug. 2021
Are you trying to add a 3rd line object to a yyaxis or are you trying to create a 3rd y-axis? There is no command to achieve the latter. The prior problem is likely an easy fix but can you guess why we can't help (yet)?
Robert Scott
Robert Scott am 13 Aug. 2021
Bearbeitet: Robert Scott am 13 Aug. 2021
i dont care how we do it but i need to ploy 5 variables on a y axis that all have different scales
I could live with 4 variables
What can i do
Adam Danz
Adam Danz am 13 Aug. 2021
I don't think you understood my first question. It's unclear to me whether you are trying to add 5 lines to a yyaxis plot (easy solution) or adding 5 axes to the plot (more difficult).
> I am trying to plot up to 5 y Variable on the same figure...
This line above suggests to me the prior (adding 5 lines).
> ...with up to 5 different y axis (and the title:) trying to plot multiple y axis
This line suggests to me that you may be trying to plot 5 axes.
Those are 2 completely different problems which need cleared up before I (any maybe others) are willing to spend time to explaining the solution.
We can't help because 1) the goal isn't clear and 2) we don't have your data (or at least a description of the data) and the code to see where the problem is.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Chunru
Chunru am 13 Aug. 2021

2 Stimmen

% data
x = (0:.1:4)';
y = [cos(2*x) exp(x) x.^2 5*sin(4*x)];
% Plot on the left and right y axes using yyaxis
hax1 = axes;
yyaxis left
plot(x, y(:, 1));
yyaxis right
plot(x, y(:,2))
% New transparent axes
hax2 = axes('position', hax1.Position);
plot(hax2, x, y(:,3), 'k')
hax2.XLim = hax1.XLim;
hax2.XTick = hax1.XTick;
hax2.YAxis.TickLabelFormat = "%g "; % use space to move left
hax2.Color = 'none'; % transparent
hax3 = axes('position', hax1.Position);
plot(hax3, x, y(:,4), 'g')
hax3.XLim = hax1.XLim;
hax3.XTick = hax1.XTick;
hax3.YAxis.TickLabelFormat = " %g"; % use space to move right
hax3.YAxis.Color = 'g';
hax3.YAxisLocation = 'right';
hax3.Color = 'none'; % transparent

4 Kommentare

Muhammad Zubair Shahid
Muhammad Zubair Shahid am 20 Apr. 2022
Hi!
I am running this code in R2021b and here is the problem, can you fix it?
make sure the following line is done AFTER plotting command.
hax2.YAxis.TickLabelFormat = "%g "; % use space to move left
Carlos Quispe Galdos
Carlos Quispe Galdos am 1 Okt. 2022
Hello folks, is it possible to replicate this on the appDesigner. I'm trying with no success
Chunru
Chunru am 2 Okt. 2022
Show what you have tried and what is the problem.

Melden Sie sich an, um zu kommentieren.

Kategorien

Produkte

Version

R2020b

Gefragt:

am 13 Aug. 2021

Kommentiert:

am 2 Okt. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by