plot a graph with two axis

1 visualizzazione (ultimi 30 giorni)
Nikolas Spiliopoulos
Nikolas Spiliopoulos il 18 Lug 2017
Hi there,
I have a matrix 1440x3 and I would like to plot a graph with two axes. (x axis the same = 1440 elements)
the first two columns vary from -0.4 to 1.2, and the third one from 80 to 90.
how can I do this?
thanks a lot
Nikolas

Risposta accettata

alice
alice il 18 Lug 2017
Modificato: alice il 18 Lug 2017
You can do like this, using yyaxis:
% fake data generation:
myMatrix = [(1.2-(-0.4))*rand(20,2)+(-0.4) , sort((90-80)*rand(20,2)+80)];
% figure with two y-axis:
figure;
yyaxis left % select the left y-axis
plot(myMatrix(:,3),myMatrix(:,1)); % plot (left y-axis)
ylabel('column 1'); % label the y-axis
yyaxis right % select the right y-axis
plot(myMatrix(:,3),myMatrix(:,2)); % plot (right y-axis)
ylabel('column 2'); % label the y-axis
xlabel('column 3');
  3 Commenti
alice
alice il 18 Lug 2017
Modificato: alice il 18 Lug 2017
OK, sorry I hadn't got you right, just modify the plots to get what you want, most probably something like:
% fake data generation:
myMatrix = [(1.2-(-0.4))*rand(1440,2)+(-0.4) , (90-80)*rand(1440,2)+80];
% figure with two y-axis:
figure;
yyaxis left % select the left y-axis
hold on;
plot(1:size(myMatrix,1),myMatrix(:,1),'k-'); % plot (left y-axis)
plot(1:size(myMatrix,1),myMatrix(:,2),'b-'); % plot (left y-axis)
yyaxis right % select the right y-axis
plot(1:size(myMatrix,1),myMatrix(:,3),'r-'); % plot (right y-axis)
legend('column 1','column 2','column 3')
xlabel('index');
Nikolas Spiliopoulos
Nikolas Spiliopoulos il 18 Lug 2017
thanks a lot it worked!!!

Accedi per commentare.

Più risposte (0)

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by