> Anyhow, if you get a python version of plsmem to work following the general
> PLplot/swig implementation overview I have described, then I would be
> pleased to accept your patch to bindings/python/plplotcmodule.i as well as
> the trivial patch for bindings/swig-support/plplotcapi.i that I
> mentioned above.
>

Turns out that the whole patch is pretty trival, see attached. The sample
script will plot to a memory buffer, and then uses PIL to write this to a
file.

You can even open an image, convert to buffer, plot and write back to
image if you want to do overlays, etc.

Have fun, and let me know if it causes any problems.
Simon.
#!/usr/bin/env python

import Image
import math
import numpy.numarray

from plplot import *

# ---------------------------------------------------
# Build random array (aka fake data)

plseed(1234)
x=[]
y=[]

for i in range(500) :
    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 = numpy.numarray.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

# ---------------------------------------------------
# Initialise buffer

# Start from a blank canvas
width = 480
height = 320
my_buffer = numpy.numarray.zeros((height,width,3), numpy.uint8)

'''
# Or open an existing image
# (note 'asarray' will fail as it sees PIL image as an array already and 
# does not perform a copy to make a writable array)
src_img = Image.open("input.png")
my_buffer = numpy.array(src_img.convert('RGB'), numpy.uint8)
(width, height) = src_img.size
'''

# ---------------------------------------------------
# Rectangular plot 

# initialise for mem driver
plsmem(width,height,my_buffer)
plstart ("mem", 1, 1);

plcol0(1)
plenv(0, 360, 0, 90, 0, 2)
plcol0(2)
pllab("Azimuth", "Elevation", "Rectangular Sky View")

# plot binned density
plimage(data, 0, 360, 0, 90, 0, max_val, 0, 360, 0, 90)

# plot points
plpoin(x,y,5)

# Use fromstring as frombuffer will invert the image
my_image = Image.fromstring("RGB", (width,height), my_buffer)
my_image.save('output.png')
plend()

Attachment: plplot_python_plsmem.patch
Description: Binary data

------------------------------------------------------------------------------
This SF.net email is sponsored by Sprint
What will you do first with EVO, the first 4G phone?
Visit sprint.com/first -- http://p.sf.net/sfu/sprint-com-first
_______________________________________________
Plplot-devel mailing list
Plplot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plplot-devel

Reply via email to