Polar contour plot with matplotlib

83 views
Skip to first unread message

Stijn Calders

unread,
Dec 6, 2012, 4:15:29 AM12/6/12
to pytho...@oma.be
Dear all,

I try to make a polar contour plot (see attachment for the desired
result) with Python and Matplotlib. I did several tests, but no success.
Could somebody give me a suggestion?

My code:
===
OF = []

import csv, os, pylab, numpy
os.chdir('c:\\Users\\stijnc\\Documents\\Reinteract\\test')

with open('of2.txt','rb') as csvfile:
line = csv.reader(csvfile, delimiter=' ')
for col in line:
OF.append(col[2])

max_OF = max(OF, key=float)
norm_OF = [float(x)/float(max_OF) for x in OF]

theta, phi = numpy.mgrid[0:95:5,0:365:5]

norm_OF = numpy.reshape(norm_OF,theta.shape)
ax = pylab.subplot(111, polar=True)
#c = pylab.pcolormesh(phi, theta, norm_OF)
#c.set_alpha(0.75)

c = pylab.contour(phi,theta,norm_OF,10,colors='k')
pylab.clabel(c, fontsize=9, inline=1)

pylab.colorbar(c)
pylab.show()
===

Many thanks in advance!
Stijn.
OF.png

Stijn Calders

unread,
Dec 14, 2012, 10:09:16 AM12/14/12
to pytho...@oma.be
Dear all,

I found the solution myself.

===
OF = []

import csv, os, pylab, numpy
os.chdir('c:\\Users\\stijnc\\Documents\\Reinteract\\test')

with open('of2.txt','rb') as csvfile:
line = csv.reader(csvfile, delimiter=' ')
for col in line:
OF.append(col[2])

theta, phi = numpy.mgrid[0:95:5,0:360:5]

OF = numpy.reshape(OF,theta.shape)
ax = pylab.subplot(111, polar=True)

c = pylab.contour(phi*3.14/180,theta,OF,10,colors='k')
pylab.clabel(c, inline=1, fontsize=10)
pylab.show()
===

Best regards,
Stijn.
--
! Please consider the environment before printing this email
________________________________________________
Stijn Calders
Services and Operations: Space Weather

Belgian Institute for Space Aeronomy (BIRA-IASB)
Ringlaan 3
B-1180 Brussels
BELGIUM

phone : +32 (0)2 373.04.19
e-mail : stijn....@aeronomie.be
web : www.aeronomie.be
________________________________________________

OF2-contour.png
Reply all
Reply to author
Forward
0 new messages