>> I've searched around but haven't found a
>> clear example, although I think its something to do with mapping 'world
>> views' and 'pltr1/pltr2'.
>
> Our standard example 16 (e.g., examples/python/xw16.py) implements a polar
> plot in its last page for all our supported languages. See
> http://plplot.sourceforge.net/examples.php?demo=16 for further details.
>
Unfortunately the examples aren't very clear (to me anyhow) and appear to
'pre-process' the data before plotting it, which isn't really making use
of the pltr2 stuff.
Digging around in the source (always the best documentation, eh) I found
this defination
--
plimagefr( img, xmin, xmax, ymin, ymax, zmin, zmax, valuemin, valuemax,
[pltr, [pltr_data] or [xg, yg, [wrap]]])
--
which lead me to write a sub-routine to manipulate the XY co-ordinates,
which I then call directly in 'plimagefr'. Working example attached.
When I attempted to apply the same approach to 'plstransform' I find it
does not work, as the parameter format is different. Why wouldn't these
behave exactly the same? (perhaps a Python binding bug).
Cheers,
Mungewell.
#!/usr/bin/env python
import math
from plplot import *
from numpy import *
# ---------------------------------------------------
# Transform for plotting polar charts
def rect2pol(az, ele, scale):
# Convert rectangular Az/Ele to polar (for 1x1 chart)
# scale is a tuple which defines scope of XY co-ords
px = math.cos(az * math.pi * 2 / scale[0])
py = math.sin(az * math.pi * 2 / scale[0])
px = (px * (scale[1] - ele) / scale[1])
py = (py * (scale[1] - ele) / scale[1])
return array((px, py))
# ---------------------------------------------------
# Build random array (aka fake data)
plseed(1234)
x=[]
y=[]
for i in range(1200) :
x.append(plrandd() * 360)
y.append(plrandd() * 90)
# compute binned density on 15' boundaries
# 360' gives 24 divisions
# 90' gives 6 divisions
width = 24
height = 6
max_val = 0
data = zeros((width,height))
for i in range(len(x)):
data[int(x[i]/(360/width))][int(y[i]/(90/height))] += 1
if data[int(x[i]/(360/width))][int(y[i]/(90/height))] > max_val:
max_val +=1
# ---------------------------------------------------
# Rectangular plot
plinit()
plcol0(1)
plenv(0, 360, 0, 90, 0, 2)
plcol0(2)
pllab("Azimuth", "Elevation", "Rectangular Sky View")
# build greyscale colour map
col = []
for i in range(16):
col.append(i*16)
plscmap1(col, col, col)
# plot binned density
plimage(data, 0, 360, 0, 90, 0, max_val, 0, 360, 0, 90)
# plot points
plpoin(x,y,5)
# ---------------------------------------------------
# Polar plot
plsori(1)
plenv(1.2, -1.2, -1.2, 1.2, 2, -2)
pllab("", "", "Polar Sky View")
# plot data (somehow....)
# plimagefr( img, xmin, xmax, ymin, ymax, zmin, zmax, valuemin, valuemax, [pltr, [pltr_data] or [xg, yg, [wrap]]])
plimagefr(data, 0, 360, 0, 90, 0, 0, 0, max_val, rect2pol, [width, height]);
# Draw radial spokes and write labels
dtr = math.pi / 180.0
for i in range(12):
theta = 30.0 * i
dx = math.cos(dtr * theta)
dy = math.sin(dtr * theta)
plcol0(1)
pljoin(0.0, 0.0, dx, dy)
plcol0(2)
text = `int(theta)`
if dy >= 0:
plptex(dx, dy, dx, dy, -0.15, text)
else:
plptex(dx, dy, -dx, -dy, 1.15, text)
# Plot points
#plstransform(rect2pol, [360, 90])
plstransform(rect2pol, None)
plpoin(x,y,5)
pleop()
plend()------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the
lucky parental unit. See the prize list and enter to win:
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Plplot-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/plplot-general