필터 지우기
필터 지우기

plot a graph with two axis

조회 수: 2 (최근 30일)
Nikolas Spiliopoulos
Nikolas Spiliopoulos 2017년 7월 18일
댓글: Nikolas Spiliopoulos 2017년 7월 18일
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

채택된 답변

alice
alice 2017년 7월 18일
편집: alice 2017년 7월 18일
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
alice
alice 2017년 7월 18일
편집: alice 2017년 7월 18일
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 2017년 7월 18일
thanks a lot it worked!!!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Annotations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by