plot a graph with two axis
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Nikolas Spiliopoulos
il 18 Lug 2017
Commentato: 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
0 Commenti
Risposta accettata
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
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');
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Annotations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!