Eliminate backtrack in graph?

5 views (last 30 days)
Kate
Kate on 11 Jun 2013
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 Comments
Angus
Angus on 11 Jun 2013
Edited: Angus on 11 Jun 2013
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 on 12 Jun 2013
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!

Sign in to comment.

Accepted Answer

the cyclist
the cyclist on 11 Jun 2013
Edited: the cyclist on 11 Jun 2013
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 Comments
Kate
Kate on 12 Jun 2013
Thanks, really helpful :)
Angus
Angus on 12 Jun 2013
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.

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!