Bala subramanian schrieb:
hai Armin,
I looked through the examples. I could not find any example of overlapping
two differnet countours on the same plot.
I think the first example filled contours does exactly that. You want to
show two contours over each other in the same plot.
You just have to substitute the Z in cset_1 with matrix_1 and in cset_2
with matrix_2. Of course it will be helpful to use different colormaps.
E.g. a grey one for the underlying contour and a colored for the top one.
x = arange(5)
y = arange(5)
x,y = meshgrid(x,y)
Z = x**2+y**2
#contourf(Z,cmap=cm.binary) # filled contours gray
contour(Z) # not filled contours colored
error = rand(x.shape[0],x.shape[1]) # to generate a new Z
Z = (x+error)**2+(y+error)**2
contour(Z) # colored not filled contours
Armin
Armin,
I tried this but what happens is it is not overlapping, actually when i call contour function for the second time with matrix2, the plot is updated with contour of matrix 2.
contour(matrix1)
contour(matrix2).
What i finally get is the contour of matrix 2 as the final plot. What i am trying to do is that, i shd have one plot, with upper left panel for matrix1 and lower right panel for matrix2 with their separation along the diagonal. I have attached an example picture like which i am trying to make.
Bala
···
On Wed, May 13, 2009 at 5:33 PM, Armin Moser <armin.moser@…2495…> wrote:
Bala subramanian schrieb:
hai Armin,
I looked through the examples. I could not find any example of overlapping
two differnet countours on the same plot.
I think the first example filled contours does exactly that. You want to
show two contours over each other in the same plot.
You just have to substitute the Z in cset_1 with matrix_1 and in cset_2
with matrix_2. Of course it will be helpful to use different colormaps.
E.g. a grey one for the underlying contour and a colored for the top one.
x = arange(5)
y = arange(5)
x,y = meshgrid(x,y)
Z = x2+y2
#contourf(Z,cmap=cm.binary) # filled contours gray
contour(Z) # not filled contours colored
error = rand(x.shape[0],x.shape[1]) # to generate a new Z
Z = (x+error)**2+(y+error)**2
contour(Z) # colored not filled contours
Armin
Hi Bala,
I'm not sure I understand, what you want, but maybe the following goes towards
your direction
# initialise two matrices with data
matrix1 = ones((4,4))
matrix2 = 2*ones((4,4))
# and one empty matrix
matrix3 = zeros((4, 4))
for i in xrange(len(matrix3[:, 0])): # all rows
for j in xrange(len(matrix3[0, :])):# all columns
if i > j: # if below diagonal take matrix1
matrix3[i, j] = matrix1[i, j]
elif i < j: # if above diagonal take matrix 2
matrix3[i, j] = matrix2[i, j]
In [40]: print matrix3
Out[40]:
array([[ 0., 2., 2., 2.],
[ 1., 0., 2., 2.],
[ 1., 1., 0., 2.],
[ 1., 1., 1., 0.]])
With that matrix3 holds elements of matrix2 in the upper part and elements of
matrix1 below the diagonal. This one could be plotted with contour or
contourf.
Is that what you want?
best regards Matthias
···
On Wednesday 13 May 2009 18:12:53 Bala subramanian wrote:
Armin,
I tried this but what happens is it is not overlapping, actually when i
call contour function for the second time with matrix2, the plot is updated
with contour of matrix 2.
contour(matrix1)
contour(matrix2).
What i finally get is the contour of matrix 2 as the final plot. What i am
trying to do is that, i shd have one plot, with upper left panel for
matrix1 and lower right panel for matrix2 with their separation along the
diagonal. I have attached an example picture like which i am trying to
make.
Bala
On Wed, May 13, 2009 at 5:33 PM, Armin Moser > > <armin.moser@...2495...>wrote:
> Bala subramanian schrieb:
> > hai Armin,
> >
> > I looked through the examples. I could not find any example of
>
> overlapping
>
> > two differnet countours on the same plot.
>
> I think the first example filled contours does exactly that. You want to
> show two contours over each other in the same plot.
> You just have to substitute the Z in cset_1 with matrix_1 and in cset_2
> with matrix_2. Of course it will be helpful to use different colormaps.
> E.g. a grey one for the underlying contour and a colored for the top one.
>
> x = arange(5)
> y = arange(5)
> x,y = meshgrid(x,y)
> Z = x**2+y**2
> #contourf(Z,cmap=cm.binary) # filled contours gray
> contour(Z) # not filled contours colored
> error = rand(x.shape[0],x.shape[1]) # to generate a new Z
> Z = (x+error)**2+(y+error)**2
> contour(Z) # colored not filled contours
>
> Armin
Matthias Michler wrote:
...
for i in xrange(len(matrix3[:, 0])): # all rows
for j in xrange(len(matrix3[0, :])):# all columns
...
if your matrices a and b are rectangular (and i think the "diagonal"
makes only sense in this case), you can also say:
array([list(a[i,:i])+list(b[i,i:]) for i in range(a.shape[0])])
best,
sebastian.
p.s.: i think it would be a nice feature to put
"matplotlib-users@lists.sourceforge.net" as reply-to in the mails
distributed via the list -- i keep hitting the 'reply'-button and wonder
why my mails do not show up in the list...
Sebastian Busch wrote:
Matthias Michler wrote:
...
for i in xrange(len(matrix3[:, 0])): # all rows
for j in xrange(len(matrix3[0, :])):# all columns
...
if your matrices a and b are rectangular (and i think the "diagonal"
makes only sense in this case), you can also say:
array([list(a[i,:i])+list(b[i,i:]) for i in range(a.shape[0])])
It seems that I did not understand what you tried to reach. Sorry for
pointing into the wrong direction.
Another possibility would be to use masked arrays:
------------------------8<-------------------------------------
from pylab import *
x = arange(100)
y = arange(100)
x,y = meshgrid(x,y)
Z = x**2+y**2
mask = ones(Z.shape)
# contour, imshow, pcolor do not show values at positions
# where the mask is True
lower_left_masked = triu(mask)==0 # lower left part in matrix masked
Z = ma.masked_array(Z,mask=lower_left_masked)
contourf(Z,origin='lower')
error = rand(x.shape[0],x.shape[1])
upper_right_masked = tril(mask)==0
Z = (x+error)**2+(y+error)**2
Z = ma.masked_array(Z,mask=upper_right_masked)
contourf(Z,cmap=cm.binary)
axis('tight')
show()
Thank you Matthias, Sebastin and Armin!!!
My matrices are square matrices and not rectangular one. I tried the way of creating a new matrix from existing ones as suggested by matthias and it worked great. I will try the masked array method too.
Thank you all once again,
Bala
···
On Wed, May 13, 2009 at 6:45 PM, Matthias Michler <MatthiasMichler@…361…> wrote:
Hi Bala,
I’m not sure I understand, what you want, but maybe the following goes towards
your direction
initialise two matrices with data
matrix1 = ones((4,4))
matrix2 = 2*ones((4,4))
and one empty matrix
matrix3 = zeros((4, 4))
for i in xrange(len(matrix3[:, 0])): # all rows
for j in xrange(len(matrix3[0, :])):# all columns
if i > j: # if below diagonal take matrix1
matrix3[i, j] = matrix1[i, j]
elif i < j: # if above diagonal take matrix 2
matrix3[i, j] = matrix2[i, j]
In [40]: print matrix3
Out[40]:
array([[ 0., 2., 2., 2.],
[ 1., 0., 2., 2.],
[ 1., 1., 0., 2.],
[ 1., 1., 1., 0.]])
With that matrix3 holds elements of matrix2 in the upper part and elements of
matrix1 below the diagonal. This one could be plotted with contour or
contourf.
Is that what you want?
best regards Matthias
On Wednesday 13 May 2009 18:12:53 Bala subramanian wrote:
Armin,
I tried this but what happens is it is not overlapping, actually when i
call contour function for the second time with matrix2, the plot is updated
with contour of matrix 2.
contour(matrix1)
contour(matrix2).
What i finally get is the contour of matrix 2 as the final plot. What i am
trying to do is that, i shd have one plot, with upper left panel for
matrix1 and lower right panel for matrix2 with their separation along the
diagonal. I have attached an example picture like which i am trying to
make.
Bala
On Wed, May 13, 2009 at 5:33 PM, Armin Moser > > > > > > <armin.moser@…2495…>wrote:
Bala subramanian schrieb:
hai Armin,
I looked through the examples. I could not find any example of
overlapping
two differnet countours on the same plot.
I think the first example filled contours does exactly that. You want to
show two contours over each other in the same plot.
You just have to substitute the Z in cset_1 with matrix_1 and in cset_2
with matrix_2. Of course it will be helpful to use different colormaps.
E.g. a grey one for the underlying contour and a colored for the top one.
x = arange(5)
y = arange(5)
x,y = meshgrid(x,y)
Z = x2+y2
#contourf(Z,cmap=cm.binary) # filled contours gray
contour(Z) # not filled contours colored
error = rand(x.shape[0],x.shape[1]) # to generate a new Z
Z = (x+error)**2+(y+error)**2
contour(Z) # colored not filled contours
Armin
The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your
production scanning environment may not be a perfect world - but thanks to
Kodak, there’s a perfect scanner to get the job done! With the NEW KODAK i700
Series Scanner you’ll get full speed at 300 dpi even with all image
processing features enabled. http://p.sf.net/sfu/kodak-com
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users
Armin Moser wrote:
Sebastian Busch wrote:
...
array([list(a[i,:i])+list(b[i,i:]) for i in range(a.shape[0])])
It seems that I did not understand what you tried to reach.
...
Sorry. I wanted to do the same as Matthias -- taking his example:
···
=====
from scipy import ones, array
matrix1 = ones((4,4))
matrix2 = 2*ones((4,4))
matrix3 = array([list(matrix1[i,:i])+list(matrix2[i,i:])\
for i in range(matrix1.shape[0])])
yields
matrix3
array([[ 2., 2., 2., 2.],
[ 1., 2., 2., 2.],
[ 1., 1., 2., 2.],
[ 1., 1., 1., 2.]])
it's quite the same, you just have to type less
best,
sebastian.
Sebastian Busch schrieb:
Armin Moser wrote:
Sebastian Busch wrote:
...
array([list(a[i,:i])+list(b[i,i:]) for i in range(a.shape[0])])
It seems that I did not understand what you tried to reach.
...
Sorry. I wanted to do the same as Matthias -- taking his example:
I meant I did not understand in the first what Bala tried to reach. I
have answered to the wrong mail and quoted badly. Sorry
Armin