plot a graph with two axis

1 次查看(过去 30 天)
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');

请先登录,再进行评论。

更多回答(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