5

I have two contour plots and I want to be able to fill from one contour in one image to the same height contour in the other.

enter image description here

In the plot you can see two lines of each color - these are the lines I want to fill between, with the same color as the lines (though preferably translucent). The code for these are as follows

test = repmat(repelem(0:6,2),10,1);
test1 = test(:,2:end-1);
test2 = test(:,1:end-2);
contour(test1,1:5);
hold on;
contour(test2,1:5);

I did think that maybe I could create another image that has the desired height at each bin and do some kind of contourf, but that could be a problem if in future the lines cross over, which they may well do. In that case, I'd like the area they cross to be a combination of the colors that are crossing over.

EBH
  • 10,350
  • 3
  • 34
  • 59
user1153070
  • 139
  • 8
  • 1
    I have edited it to a generic example that anyone should be able to reproduce :) – user1153070 Jun 15 '17 at 08:15
  • 3
    There are several similar questions like [here](https://stackoverflow.com/questions/6245626/matlab-filling-in-the-area-between-two-sets-of-data-lines-in-one-figure), [here](https://stackoverflow.com/questions/4698679/shading-between-vertical-lines-in-matlab), [here](https://stackoverflow.com/questions/20366120/how-to-fill-color-inside-multiple-contour-line-in-the-matlab), and [here](https://stackoverflow.com/questions/38662310/matlab-filled-contour-plot-with-imcontour) (that's all I had room for in a comment). Are none of these applicable to your situation? – beaker Jun 15 '17 at 15:15
  • Possible duplicate of [Shading between vertical lines in MATLAB](https://stackoverflow.com/questions/4698679/shading-between-vertical-lines-in-matlab) – Finn Jan 10 '19 at 13:47

1 Answers1

1

Have you try using ```fill``?

% test values
col = 'g';
x1=[6 6 6];y1=[1 5 10]; x2= [7 7 7];

x2 = [x1, fliplr(x2)];
inBetween = [y1, fliplr(y1)];
fill(x2, inBetween, col);
lhoupert
  • 584
  • 8
  • 25