plot a graph with two axis
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Nikolas Spiliopoulos
am 18 Jul. 2017
Kommentiert: Nikolas Spiliopoulos
am 18 Jul. 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
0 Kommentare
Akzeptierte Antwort
alice
am 18 Jul. 2017
Bearbeitet: alice
am 18 Jul. 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 Kommentare
alice
am 18 Jul. 2017
Bearbeitet: alice
am 18 Jul. 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');
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Annotations finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!