How to make filled contour plot
5 次查看(过去 30 天)
显示 更早的评论
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?
0 个评论
回答(2 个)
Russel Burgess
2021-3-8
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().
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!