# [SciPy-User] conotur plot

Sebastian sebas0@gmail....
Thu Mar 29 12:59:42 CDT 2012

```Thanks for the help Aronne, just some feedback on post 6 of SciPy-User
Digest, Vol 103, Issue 65

Even though both solution plots contours both sets of contours are
off-center (axis inverted). and so they don't follow the density of points,
as intended.

The solution was proposed by Octavia Bruzzone.

Changing:

z1=N.zeros((x1.shape[0],y1.shape[0]),yc1.dtype)

to

z1=N.zeros((y1.shape[0],x1.shape[0]),yc1.dtype)

and then plotting contours as normal

pylab.contour(x1,y1,z1*100/len(magk),30,alpha=0.5,linewidths=5)

best wishes,
- Sebastian

I'm trying to make a contour plot of astronomical data binning data in a 2D
> grid. When I bin the data in square bins (eg 60 x 60), the contour plot
> works fine. But if I change the binning to (10 x 60), by changing the
> following line in  the code, from:
>
> "resolucion_x1=(xc1.max()-xc1.min())/(nceldas)"
> to
> "resolucion_x1=3* (xc1.max()-xc1.min())/(nceldas)"
>
> then I produce three arrays  (x1,y1,z1)
> with size 20,60,1200 instead of 60,60,3600
> BUT when I try plot a contour map with pylab.contour I get the follow
> error:
>
> "
> TypeError: Length of x must be number of columns in z,
> and length of y must be number of rows."
> and I think this occurs because:
>
> In [788]: shape(x1),shape(y1),shape(z1)
> Out[788]: ((20,), (60,), (20, 60))
>
> Any idea as to how to solve this so I can use rectangular binning
> with the code?
>
> I use the following code:
>
> import numpy as N
> from subprocess import *
> import pyfits
> import matplotlib
> import pylab
> import pickle
> from itertools import izip
>
>
>
> xc1=N.array(magj-magk)
> yc1=N.array(magk)
> print ("xc1 max",xc1.max())
> print ("yc1 max",yc1.max())
> print ("xc1 min",xc1.min())
> print ("yc1 min",yc1.min())
> print ("is nonnum",N.isnan(xc1).any())
> nceldas=60.0
> resolucion_x1=(xc1.max()-xc1.min())/(nceldas)
> resolucion_y1=(yc1.max()-yc1.min())/(nceldas)
> minix1=xc1.min();miniy1=yc1.min()
> x1=N.arange(xc1.min(),xc1.max(),resolucion_x1,dtype=xc1.dtype)
> y1=N.arange(yc1.min(),yc1.max(),resolucion_y1,dtype=yc1.dtype)
> z1=N.zeros((x1.shape[0],y1.shape[0]),yc1.dtype)
> print "x1 size" , x1.size
> print "y1 size" , y1.size
> print "z1 size" , z1.size
>
> xc1=(xc1-xc1.min())/resolucion_x1
> yc1=(yc1-yc1.min())/resolucion_y1
> print xc1.max(), xc1.min(),yc1.max(),yc1.min()
> for i,j in zip(xc1,yc1):
>    try: z1[int(j),int(i)]+=1.0
>    except: pass
>
> figure=pylab.figure()
> pylab.plot(magj-magk,magk,'b.',ms=2.3,alpha=0.70)
> pylab.ylim(pylab.ylim()[::-1])
> pylab.contour(x1,y1,z1*100/len(magk),30,alpha=1,linewidths=5)
> pylab.show()
>
> confused...
> - Sebastian
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20120329/1ed75037/attachment.html
```