How to make filled contour plot

5 views (last 30 days)
mukesh bisht
mukesh bisht on 8 Mar 2021
Answered: mukesh bisht on 9 Mar 2021
I want to plot a filled contour for the following case: I have a column vector A= [1; 1; 2; 1; 2; 2; 1; 2; 1; 2] containing two size particles (1&2). Over the time, the values in the vector A get segreggated i.e. after some time interval(discrete) vector becomes A = [1;1;1;1;1;2;2;2;2;2]. Now I want a filled contour plot for this time dependent segregation with value 2 represented by blue color and value 1 represented by orange color. How to do it?

Answers (2)

Russel Burgess
Russel Burgess on 8 Mar 2021
Assuming you have many values of A across time, you could do this by assembling them into a matrix to be fed into contourf(), then use colormap() to set the colours. For example, if the matrix of A changing over time is (each row is a new value of A in time):
A = [1 1 2 1 2 2 1 2 1 2; ...
1 1 2 1 2 2 1 1 2 2; ...
1 1 1 2 2 1 2 1 2 2; ...
1 1 1 2 2 1 1 2 2 2; ...
1 1 1 2 1 1 2 2 2 2; ...
1 1 1 1 2 1 2 2 2 2; ...
1 1 1 1 1 2 2 2 2 2]';
Then you can plot this out by:
contourf(A, 1);
colormap([1 0.5 0; 0 0 1]);
The second argument to contourf() specifies to use only one contour (so, two regions). The arguments to colourmap() specify the RGB colours - in this case orange for the lowest value and blue for the highest. You can feed values for the x/y axes into contourf() in the same way as contour().

mukesh bisht
mukesh bisht on 9 Mar 2021
I am getting this type of contour. But i want that the colours do not appear in patches instead a mixed colour (orange & blue) as if the colours are flowing with time. How to do that?

Categories

Find more on Contour Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!