I am trying to write my own plot function. Being that their are many plotting methods available, you may ask WHY? I am working on a program that can take data from some file and spit out a plot of the data to a png file.
At the moment I am using numeric python for handling the data. My goal is to use PIL (python imaging library) to actually create the image files. To start, I am using black and white imaging. My logic is outlined in the following ridiculously? simple code:
#!/usr/bin/python
#from NumTut import *
from PIL import Image
from numpy import *
def mkcheckerboard(n):
"""
Create a checkerboard of shape (n,n)
"""
#brute force
Brd=zeros((n,n))
seq01=gen_bin_seq(n,-1)
seq10=gen_bin_seq(n,1)
#set even rows to 0,1,0...
Brd[0::2]=seq01
Brd[1::2]=seq10
return Brd
def gen_bin_seq(n,sign=-1):
"""
Generate a binary sequence
i.e. (0,1,0,1...) of length n
For sign=-1, start with 0,
for sign=+1, start with 1.
"""
seq=arange(0,n)
i=0
while i!=n:
seq[i]=0.5*( 1 + sign*(-1)**(i+1) )
i+=1
return seq
def mkpng(Brd):
"""
Create image from array Brd
"""
img=Image.frombuffer('L',(8,8),ravel(B*255).astype('uint8')) #create b&w image from data
img.save('/tmp/ckboard.png')
return
This is simple because I can set each bit very quickly. However, for the actual program I will need to draw an image containing a line containing all the data values. The problem is there will be a lot of data and I cannot simply set individual pixels as that will take too long?
My thought was to create 640x480 array of white pixels then calculate pixel "height" indices from every value in the data. Then set the calculated indices to black, this should create a scatter type plot.
The issue is:
-there is more data than pixels, so some value have to overlap?
-one pixel may not even be visible, so I might have to set more than one pixel for a single value.
As you can tell I am a complete noob at low level graphics.
Does anyone have any suggestions or can anyone point me to some source code for low level plot generation?
Thanks

New Topic/Question
Reply




MultiQuote





|