pcolor in Matlab

  • Follow


Hi All,

I have been trying to use pcolor for plotting but have had no success
for the past whole week.  For example, if b1 and b2 are variables from
the numerical solution of a pde then I set

parameter1=linspace(.....);
parameter2=linspace(.....);

loop for parameter 1 and 2

D=b1-b2;
find(D<0)

pcolor(parameter1,parameter2, when is D negative )

Basically I want it to give the plot a green color if D is negative
only in the region 0<x<25, blue if D is negative only in 25<x<50,.....
and so on.

I very much appreciate it if someone can shed some light on this, as I
have been trying all week to get it right but no hope.

Cheers,

Emma
0
Reply MA87 (38) 6/1/2010 4:14:57 PM

FRUITS wrote:

> I have been trying to use pcolor for plotting but have had no success
> for the past whole week.  For example, if b1 and b2 are variables from
> the numerical solution of a pde then I set
> 
> parameter1=linspace(.....);
> parameter2=linspace(.....);
> 
> loop for parameter 1 and 2
> 
> D=b1-b2;
> find(D<0)
> 
> pcolor(parameter1,parameter2, when is D negative )
> 
> Basically I want it to give the plot a green color if D is negative
> only in the region 0<x<25, blue if D is negative only in 25<x<50,.....
> and so on.

You are trying to mix two modes of pcolor. pcolor() can color a matrix 
on your behalf according to value if you give it only the matrix of 
values; in that case that you supply x and y coordinates, then you must 
supply a color value for each coordinate pair and so must pre-compute 
the appropriate color values yourself.

What shape is D? is it length(parameter1) by length(parameter2) ?
0
Reply Walter 6/1/2010 4:33:04 PM


On Jun 1, 5:33=A0pm, Walter Roberson <rober...@hushmail.com> wrote:
> FRUITS wrote:
> > I have been trying to use pcolor for plotting but have had no success
> > for the past whole week. =A0For example, if b1 and b2 are variables fro=
m
> > the numerical solution of a pde then I set
>
> > parameter1=3Dlinspace(.....);
> > parameter2=3Dlinspace(.....);
>
> > loop for parameter 1 and 2
>
> > D=3Db1-b2;
> > find(D<0)
>
> > pcolor(parameter1,parameter2, when is D negative )
>
> > Basically I want it to give the plot a green color if D is negative
> > only in the region 0<x<25, blue if D is negative only in 25<x<50,.....
> > and so on.
>
> You are trying to mix two modes of pcolor. pcolor() can color a matrix
> on your behalf according to value if you give it only the matrix of
> values; in that case that you supply x and y coordinates, then you must
> supply a color value for each coordinate pair and so must pre-compute
> the appropriate color values yourself.
>
> What shape is D? is it length(parameter1) by length(parameter2) ?

Thanks for replying.  Here is my basic code

param1s=3Dlinspace(....);
param2s=3Dlinspace(....);

Ldiff=3D[];

for j=3D1:length(param1s)
     pars.param1=3Dparam1s(j);

    for i=3D1:length(param2s)
         pars.param2=3Dparam2s(i);

        "run" my other program successively with those param1 and 2

        D=3Db1-b2;
        Ldiff(i,j)=3Dlength(find(D<0));
    end
end

pcolor(param1s,param2s,double(Ldiff>0))


However, this is general and does NOT incorporate each range of x
(spatial variable) where D is negative a different colour.
0
Reply FRUITS 6/1/2010 4:53:18 PM

FRUITS <MA87@HOTMAIL.CO.UK> wrote in message <8eb9f4b5-feb1-4fd4-88b7-2dfcfd77085c@v37g2000vbv.googlegroups.com>...
> Hi All,
> 
> I have been trying to use pcolor for plotting but have had no success
> for the past whole week.  For example, if b1 and b2 are variables from
> the numerical solution of a pde then I set
> 
> parameter1=linspace(.....);
> parameter2=linspace(.....);
> 
> loop for parameter 1 and 2
> 
> D=b1-b2;
> find(D<0)
> 
> pcolor(parameter1,parameter2, when is D negative )
> 
> Basically I want it to give the plot a green color if D is negative
> only in the region 0<x<25, blue if D is negative only in 25<x<50,.....
> and so on.
> 
> I very much appreciate it if someone can shed some light on this, as I
> have been trying all week to get it right but no hope.
> 
> Cheers,
> 
> Emma

a hint:

     help patch;

us
0
Reply us 6/1/2010 4:54:04 PM

On Jun 1, 5:54=A0pm, "us " <u...@neurol.unizh.ch> wrote:
> FRUITS <M...@HOTMAIL.CO.UK> wrote in message <8eb9f4b5-feb1-4fd4-88b7-2df=
cfd770...@v37g2000vbv.googlegroups.com>...
> > Hi All,
>
> > I have been trying to use pcolor for plotting but have had no success
> > for the past whole week. =A0For example, if b1 and b2 are variables fro=
m
> > the numerical solution of a pde then I set
>
> > parameter1=3Dlinspace(.....);
> > parameter2=3Dlinspace(.....);
>
> > loop for parameter 1 and 2
>
> > D=3Db1-b2;
> > find(D<0)
>
> > pcolor(parameter1,parameter2, when is D negative )
>
> > Basically I want it to give the plot a green color if D is negative
> > only in the region 0<x<25, blue if D is negative only in 25<x<50,.....
> > and so on.
>
> > I very much appreciate it if someone can shed some light on this, as I
> > have been trying all week to get it right but no hope.
>
> > Cheers,
>
> > Emma
>
> a hint:
>
> =A0 =A0 =A0help patch;
>
> us

....but I am sure it can be done in pcolor rather than patch.
0
Reply FRUITS 6/1/2010 5:11:13 PM

FRUITS wrote:
> On Jun 1, 5:33 pm, Walter Roberson <rober...@hushmail.com> wrote:

>> What shape is D? is it length(parameter1) by length(parameter2) ?

> Thanks for replying.  Here is my basic code

>         D=b1-b2;

You have not indicated the shape of b1 or b2, so I cannot tell what 
shape D is ?

 > pcolor(param1s,param2s,double(Ldiff>0))

Please be more specific about how you want to color the areas where D is 
non-negative.


 > Ldiff(i,j)=length(find(D<0));

Ldiff(i,j) = any(D<0);

would be more efficient.


 > pcolor(param1s,param2s,double(Ldiff>0))

Your pcolor has param1s in the first argument, the one for x, but your 
double for loop indexes param1s in the outer loop, j, which you use as 
the second index of Ldiff, which is normally the position used for y 
rather than x. If the lengths of param1s and param2s are not the same, 
then this will cause your pcolor() call to fail.

As you referenced x as being the variable you wanted to vary the color 
over, we need you to be clearer about whether that is the first or 
second index of Ldiff.
0
Reply Walter 6/1/2010 5:17:44 PM

On Jun 1, 6:17=A0pm, Walter Roberson <rober...@hushmail.com> wrote:
> FRUITS wrote:
> > On Jun 1, 5:33 pm, Walter Roberson <rober...@hushmail.com> wrote:
> >> What shape is D? is it length(parameter1) by length(parameter2) ?
> > Thanks for replying. =A0Here is my basic code
> > =A0 =A0 =A0 =A0 D=3Db1-b2;
>
> You have not indicated the shape of b1 or b2, so I cannot tell what
> shape D is ?
>

sorry, b1 and b2 are the numerical solutions of my pde and when
plotted against x at steady state they look like a quadratic function.

> =A0> pcolor(param1s,param2s,double(Ldiff>0))
>
> Please be more specific about how you want to color the areas where D is
> non-negative.

I want to loop through "my other program" using param1(i) and
param2(j) and see if b1-b2 is becoming negative anywhere in my spatial
domain as the parameters are changing.  param(i) is varying for
example from 0 to 100 in 100 steps ... etc

>
> =A0> Ldiff(i,j)=3Dlength(find(D<0));
>
> Ldiff(i,j) =3D any(D<0);
>
> would be more efficient.

>
> =A0> pcolor(param1s,param2s,double(Ldiff>0))
>
> Your pcolor has param1s in the first argument, the one for x, but your
> double for loop indexes param1s in the outer loop, j, which you use as
> the second index of Ldiff, which is normally the position used for y
> rather than x.

thanks for pointing that out, I will double check it.

If the lengths of param1s and param2s are not the same,
> then this will cause your pcolor() call to fail.
>

The lengths are the same.  The pcolor is working, but it is not
exactly how I want it to present the results.

> As you referenced x as being the variable you wanted to vary the color
> over, we need you to be clearer about whether that is the first or
> second index of Ldiff.

maybe this is not so clear. The pcolor I want is param1 vs param2 vs
where D is negative.

Specifically, I want to include in the code not only if D is negative
or not, but where in the spatial domain is it negative.  E.g, If it is
negative where x<(somevalue) then colour it blue.  If it is negative
where x>(somevalue) then colour it red....etc

Note: I am not plotting x in the pcolor...x is only involved in my
"other program" that solves the set of pdes.


I hope it is a bit clearer now, thanks.


0
Reply FRUITS 6/1/2010 5:48:05 PM

FRUITS wrote:

>> Please be more specific about how you want to color the areas where D is
>> non-negative.

> I want to loop through "my other program" using param1(i) and
> param2(j) and see if b1-b2 is becoming negative anywhere in my spatial
> domain as the parameters are changing.  param(i) is varying for
> example from 0 to 100 in 100 steps ... etc

You indicated that when 0 < x < 25, you want negative values to be green, and 
when 25 < x < 50, you want negative values to be blue. Now suppose I find a 
point for which 0 < x < 25, but the point has no associated negative values: 
what color should the point be colored? What if the point with no negative 
values where in 25 < x < 50, then what color should it be colored? What if the 
point has associated negative values but for the point, x is 25 _exactly_ and 
thus does not fall into either the green region (which needs less than 25) nor 
the blue region (which needs more than 25) ?


>> As you referenced x as being the variable you wanted to vary the color
>> over, we need you to be clearer about whether that is the first or
>> second index of Ldiff.
> 
> maybe this is not so clear. The pcolor I want is param1 vs param2 vs
> where D is negative.
> 
> Specifically, I want to include in the code not only if D is negative
> or not, but where in the spatial domain is it negative.  E.g, If it is
> negative where x<(somevalue) then colour it blue.  If it is negative
> where x>(somevalue) then colour it red....etc
> 
> Note: I am not plotting x in the pcolor...x is only involved in my
> "other program" that solves the set of pdes.

Do I understand correctly that x is a variable involved in the section you 
marked as "run my program with these parameters" ? That after that section of 
code, we can count on x having a value? If so, then is x relatively easily 
predictable based on the parameters (which might allow us to color sections of 
the array at one time), or should x be treated as "sufficiently magic" in the 
parameters that we should just do the color selection point by point?
0
Reply Walter 6/1/2010 7:40:18 PM

On Jun 1, 8:40=A0pm, Walter Roberson <rober...@hushmail.com> wrote:
> FRUITS wrote:
> >> Please be more specific about how you want to color the areas where D =
is
> >> non-negative.
> > I want to loop through "my other program" using param1(i) and
> > param2(j) and see if b1-b2 is becoming negative anywhere in my spatial
> > domain as the parameters are changing. =A0param(i) is varying for
> > example from 0 to 100 in 100 steps ... etc
>
> You indicated that when 0 < x < 25, you want negative values to be green,=
 and
> when 25 < x < 50, you want negative values to be blue. Now suppose I find=
 a
> point for which 0 < x < 25, but the point has no associated negative valu=
es:
> what color should the point be colored? What if the point with no negativ=
e
> values where in 25 < x < 50, then what color should it be colored? What i=
f the
> point has associated negative values but for the point, x is 25 _exactly_=
 and
> thus does not fall into either the green region (which needs less than 25=
) nor
> the blue region (which needs more than 25) ?

This is exactly what I want to do.  I want to give any negative values
that happen to occur in the region  0 <=3D x <=3D 25 a specific color
(say,green), (as long as the negative points are in the region, it
does not matter how many negative points I have - i.e the length),
and the ones in the region 25 <=3D x <=3D 50 another color and 0 <=3D x <=
=3D
50 (ie. the whole x domain) another color.

If I dont have any negative values in any region I also want to give
it another color...so, in total I need to assign 4 different colors to
4 different cases.

I think it is fairly straightforward to implement, but I have had no
hopes with it so far.  Maybe someone can enlighten me, Thanks!




>
> >> As you referenced x as being the variable you wanted to vary the color
> >> over, we need you to be clearer about whether that is the first or
> >> second index of Ldiff.
>
> > maybe this is not so clear. The pcolor I want is param1 vs param2 vs
> > where D is negative.
>
> > Specifically, I want to include in the code not only if D is negative
> > or not, but where in the spatial domain is it negative. =A0E.g, If it i=
s
> > negative where x<(somevalue) then colour it blue. =A0If it is negative
> > where x>(somevalue) then colour it red....etc
>
> > Note: I am not plotting x in the pcolor...x is only involved in my
> > "other program" that solves the set of pdes.
>
> Do I understand correctly that x is a variable involved in the section yo=
u
> marked as "run my program with these parameters" ? That after that sectio=
n of
> code, we can count on x having a value? If so, then is x relatively easil=
y
> predictable based on the parameters (which might allow us to color sectio=
ns of
> the array at one time), or should x be treated as "sufficiently magic" in=
 the
> parameters that we should just do the color selection point by point?


yes, x is just a spatial independent variable of the pde.
0
Reply FRUITS 6/2/2010 12:07:48 AM

FRUITS wrote:

> This is exactly what I want to do.  I want to give any negative values
> that happen to occur in the region  0 <= x <= 25 a specific color
> (say,green), (as long as the negative points are in the region, it
> does not matter how many negative points I have - i.e the length),
> and the ones in the region 25 <= x <= 50 another color and 0 <= x <=
> 50 (ie. the whole x domain) another color.
> 
> If I dont have any negative values in any region I also want to give
> it another color...so, in total I need to assign 4 different colors to
> 4 different cases.

We are getting closer, but I do not understand the bit about the whole x 
domain. You appear to be saying that when 0 <= x < 25, that you want to 
color the point both the first color _and_ the third color, since 0 <= x 
< 25 is also part of the range 0 <= x <= 50; likewise, 25 < x <= 50 
should be colored both the second and third color, and 25 exactly, which 
falls under all three conditions, should be all three colors simultaneous.
0
Reply Walter 6/2/2010 3:25:13 AM

On Jun 2, 4:25=A0am, Walter Roberson <rober...@hushmail.com> wrote:
> FRUITS wrote:
> > This is exactly what I want to do. =A0I want to give any negative value=
s
> > that happen to occur in the region =A00 <=3D x <=3D 25 a specific color
> > (say,green), (as long as the negative points are in the region, it
> > does not matter how many negative points I have - i.e the length),
> > and the ones in the region 25 <=3D x <=3D 50 another color and 0 <=3D x=
 <=3D
> > 50 (ie. the whole x domain) another color.
>
> > If I dont have any negative values in any region I also want to give
> > it another color...so, in total I need to assign 4 different colors to
> > 4 different cases.
>
> We are getting closer, but I do not understand the bit about the whole x
> domain. You appear to be saying that when 0 <=3D x < 25, that you want to
> color the point both the first color _and_ the third color, since 0 <=3D =
x
> < 25 is also part of the range 0 <=3D x <=3D 50; likewise, 25 < x <=3D 50
> should be colored both the second and third color, and 25 exactly, which
> falls under all three conditions, should be all three colors simultaneous=
..


Let me say that again.  I loop through my "other program" using
params1 and params2.
If D is ALWAYS negative in the region from x=3D0 to x=3D50 (and say 50 is
the end of the spatial domain)
then I would give it a specific color.

If D is negative ONLY from x=3D0 to x=3D25 then I give it another color.

If D is negative ONLY from x=3D25 to x=3D50 then I give it another color.

If D is non-negative anywhere then I give it another color.

I just want to know how to color these regions using pcolor.
Please let me know if you need any clarifications.







0
Reply FRUITS 6/2/2010 10:19:27 AM

FRUITS wrote:

> Let me say that again.  I loop through my "other program" using
> params1 and params2.
> If D is ALWAYS negative in the region from x=0 to x=50 (and say 50 is
> the end of the spatial domain)
> then I would give it a specific color.
> 
> If D is negative ONLY from x=0 to x=25 then I give it another color.
> 
> If D is negative ONLY from x=25 to x=50 then I give it another color.
> 
> If D is non-negative anywhere then I give it another color.

Is it the case that at each step, x is a vector of values, each in the 
range 0 to 50 and that D is the same length as x, with each element of D 
corresponding to the x in the same position? If so, then is x always a 
full vector from 0 to 50, or does it sometimes cover only part of that 
range? Is 25 certain to be at the mid-point of the vector of x? Is x 
sorted in ascending order?

If x _is_ a vector of values ranging from 0 to 50, and if you want the 
colors to be determined point-wise, then please clarify which color you 
would want for the following cases:

- No D are negative

- some but not all D corresponding to 0 to 25 are negative, and no D 
corresponding to 25 to 50 are negative

- all D corresponding to 0 to 25 are negative, and no D corresponding to 
25 to 50 are negative

- no D corresponding to 0 to 25 are negative, and some but not all D 
corresponding to 25 to 50 are negative

- some but not all D corresponding to 0 to 25 are negative, and some but 
not all D corresponding to 25 to 50 are negative

- all D corresponding to 0 to 25 are negative, and some but not all D 
corresponding to 25 to 50 are negative

- no D corresponding to 0 to 25 are negative, and all D corresponding to 
25 to 50 are negative

- some but not all D corresponding to 0 to 25 are negative, and all D 
corresponding to 25 to 50 are negative

That is 8 possible cases -- more if you wish to detect D equal to 0.


Please also decide (arbitrarily if necessary) which of the two sides you 
want x exactly equal to 25 to fall into. It is computationally more 
efficient if you have x exactly equal to 25 fall into the first half.


The alternative to all of this is that x is, after each run, a single 
value that is in the range 0 to 50, and that you are asking that the 
entire graph be colored one color if all of the D are negative at every 
iteration, and that each location which ended up with an x from 0 to 25 
be colored with a second color if all of the D are negative at those 
locations, and that each location which ended up with an x from 25 to 50 
be colored with a third color if all of the D are negative at those 
locations. This leaves open the question of what colors you would wish 
to use if somewhere in the graph, there was a location in which at least 
one D was non-negative, and so on.
0
Reply Walter 6/2/2010 3:27:30 PM

11 Replies
330 Views

(page loaded in 0.13 seconds)

Similiar Articles:


















7/17/2012 6:49:16 PM


Reply: