Eliminate backtrack in graph?

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