필터 지우기
필터 지우기

Eliminate backtrack in graph?

조회 수: 4 (최근 30일)
Kate
Kate 2013년 6월 11일
Hi there! I've attached a figure below which graphs changes in flux by season. Problem: Matlab is currently drawing lines in between the beginning and end of my seasons, making the graphs look odd. Is there a simple way to keep it from doing this?
Thanks a bunch!
subplot(2,2,3)
plot(Fall(:,2),Fall(:,3))
title('Fall')
subplot(2,2,4)
plot(Wtr(:,2),Wtr(:,3))
title('Wtr')
subplot(2,2,1)
plot(Spr(:,2),Spr(:,3))
title('Spr')
subplot(2,2,2)
plot(Sum(:,2),Sum(:,3))
title('Sum')
  댓글 수: 3
Angus
Angus 2013년 6월 11일
편집: Angus 2013년 6월 11일
It seems like it is plotting more than just a single data set for each plot, or the 'y' data domain is larger than the plotting window. Im not sure what is going on but what are the dimensions of Fall(:,2) and Fall(:,3)? What types are they? Ill see if I can find an example of this elsewhere.
Cheers, Angus
(You may want to avoid using variable names that are also built-in functions, such as sum, it may end up in confusing errors if you drop a capital)
Kate
Kate 2013년 6월 12일
Thanks Angus, helpful hints. Each season in this case includes multiple years of flux data. This is basically a check to make sure I don't have any wacky data years or to point out specific years of interest that are anomalous.
I appreciate the help!

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

채택된 답변

the cyclist
the cyclist 2013년 6월 11일
편집: the cyclist 2013년 6월 11일
The default line style for plot() is the draw a line between each pair of points. If it is OK to not have any of those lines, then you could plot just the data points, for example
plot(Fall(:,2),Fall(:,3),'.')
However, if you want the lines except when it "backtracks", then probably need to split your data into separate series for plotting. You could do this by deftly inserting NaN into your vectors where the backtracking occurs. Here is a simple example of what I mean. Notice the difference between the two plots.
x1 = [1 2 3 1 2 3];
y1 = [1 2 3 3 4 5];
figure
plot(x1,y1,'-')
x2 = [1 2 3 nan 1 2 3];
y2 = [1 2 3 nan 3 4 5];
figure
plot(x2,y2,'-')
  댓글 수: 2
Kate
Kate 2013년 6월 12일
Thanks, really helpful :)
Angus
Angus 2013년 6월 12일
Ahhh, repeated 'x' values, that is how that happens hey? Good to know, I hadn't thought of that. As you mentioned above about it being multiple data years you might want to consider plotting it so that they are separate lines with distinct colors. I imagine this would help keep track of which year you were looking at.
xF = Fall(1:100,2) % Whatever the full range is
xW = Wtr(1:100,2)
%etc.
subplot(2,2,3)
plot(xF,Fall(1:100,3),xF,Fall(101:200,3),xF,Fall(201:300,3))
%This will eliminate backtracks and give them distinct colors for each year
title('Fall')
subplot(2,2,4)
plot(xF,Wtr(1:100,3),xF,Wtr(101:200,3),xF,Wtr(201:300,3))
%The colors will match the ones used in the Fall plot
title('Wtr')
%etc.
Glad you got it figured out, have a good one.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by