I want to obtain the following plot.
I have 4 matrices I would say one for each line. In the matrices there are zeros and ones. Each matrix define a subset of the plane. They hinted me to use contourf command in MATLAB but I cannot obtain the exact result. First of all I tried to sum the matrices but then I understand that with this tecnique there will be two areas with the same values and so the same color. Then I tried with the hold on but since contourf plot has only colors with alpha = 1, it shows me only the last contourf plot and not the previuos ones.
My target is to replicate as near as I can the above plot in MATLAB. Any hits? Thanks in advance.

2 Comments

Attach the data...first guess w/o really seeing what is in each would be to scale the four regions and then sum...presuming the areas of each array cover the full space identically.
Giacomo Tabarelli
Giacomo Tabarelli on 25 Oct 2020
Edited: Giacomo Tabarelli on 25 Oct 2020
The matrices cover all the space identically. I attach the data. Also attach my code. Another thing I cannot understand is why I have two white areas if they have different values?

Sign in to comment.

 Accepted Answer

dpb
dpb on 25 Oct 2020
contourf(X,Y,rhosS+2*rhoEm+3*rhoImPl+4*rhoPl)
yields
You can set colors as wish...just need to scale the overlapping portions of the images to make them have different levels.
What is this a representation of, out of curiosity? Your data don't follow the pattern of the example exactly, but similar. This ends up with five unique areas by the automagic contour lines drawn...outside the upper right yellow region, that is.

4 Comments

Giacomo Tabarelli
Giacomo Tabarelli on 25 Oct 2020
Edited: Giacomo Tabarelli on 25 Oct 2020
I already tried to scale as you said and as you can see from my code. There is only one pb. Why I get two areas with the same color using a colormap with 6 custom colors? I want to have the white color as last color.
The regions represent stability regions for some Stochastic Lawson numerical methods. On the axis there are parameters used in the model. h is the step size.
Finally, is there a way to get some transparency? Or to get colored lines at each level as there is in the plot I attached in the original question?
Hmmm...I see I misread your code in the glance-over; yes, you did the same.
I played around a little more last night; the contour object is another one that is pretty-much opaque and not much useful doc for. In above answer I had presumed it was the combining by weighting that hadn't gotten and also that there would be a Color and/or CData property to set by the contour region to use to set colors.
As far as the colormap problem, there are seven unique levels in the overall Z array --
>> unique(Z(:))
ans =
0
1.00
3.00
4.00
7.00
8.00
10.00
>>
but
contourf(X,Y,rhosS)
shows that the level==1 value is occluded by the level==3 region so those two don't show separately.
I've got other demands right now, but I think perhaps the choice of weights is the problem, by using 1:4, 1+2 == 3 and 1+3 == 4 so those end up being the same.
Have to think about a way to generate weights so the levels are all still unique when combined...
dpb
dpb on 26 Oct 2020
Edited: dpb on 26 Oct 2020
Z=rhosS+2*rhoEm+4*rhoImPl+8*rhoPl; % using pow2 weighting avoid overlapping
[M,hC]=contourf(X,Y,Z);
colormap(cmap)
caxis([min(Z(:)) max(Z(:))])
yields
I can't explain why caxis doesn't cover the range by default.
As for the lines, that can be done -- follow the link in the contourf doc to the "Contour Properties" page and it shows how there.
I gotta run now, can come check in later on...

Sign in to comment.

More Answers (0)

Categories

Products

Asked:

on 25 Oct 2020

Edited:

dpb
on 26 Oct 2020

Community Treasure Hunt

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

Start Hunting!