[reportlab-users] plotting points on a jpg

Robin Becker robin at reportlab.com
Thu Nov 10 05:36:59 EST 2005


Britt Hibbert wrote:
>     
> Hi All, 
> 
> 
> I am trying to plot points, along with labels, on a jpg image. I have a graph that is split into four quadrants,  and have to place points in various sections of these quadrants based on specific data. As an example of this, I have been looking at how the pdfmap tool does this.
>   I am planning on using a jpg image as a background and plotting points on top of this jpg, using the canvas object. Before I get too far into this, I am just wondering if there is a higher level way of doing this. My use of reportlab so far has been limited to Platypus and Flowables, so I am a little wary of diving into canvas objects and then integrating this with my current use of flowables. Is there a higher level way of doing what I need, or examples posted somewhere of how to do this?
> 
> 
> Thanks in advance for any help
> Britt Hibbert
You probably want to make a Drawing which is the same size as the jpeg; you can 
then add the various bits in the __init__ method. Drawings are already flowables 
so they know how to draw themselves.

This is the sort of thing that can be knocked together fairly swiftly
########
#Autogenerated by ReportLab guiedit do not edit
from reportlab.graphics.widgets.markers import Marker
from reportlab.graphics.shapes import Drawing, _DrawingEditorMixin, Image, Line
from reportlab.lib.colors import red, blue, green

class Example(_DrawingEditorMixin,Drawing):
	def __init__(self,width=400,height=200,*args,**kw):
		apply(Drawing.__init__,(self,width,height)+args,kw)
		self.background = Image(0,0,self.width,self.height,'bgsample.jpg')
		self._data=kw.get('_data',[(100,200),(150,32)])
	 
self._add(self,Line(0,self.height*0.5,self.width,self.height*0.5,strokeWidth=2,strokeColor=red),name=None,validate=None,desc=None)
	 
self._add(self,Line(self.width*0.5,0,self.width*0.5,self.height,strokeWidth=1.5,strokeColor=blue),name=None,validate=None,desc=None)
		for x,y in self._data:
			m = Marker()
			m.kind = 'StarFive'
			m.x = x
			m.y = y
			m.size = 7
			m.fillColor = green
			self._add(self,m,name=None,validate=None,desc=None)

if __name__=="__main__": #NORUNTESTS
	Example(_data=[(13,17),(45,11),(200,179),(390,189)]).save(formats=['pdf'],outDir='.',fnRoot='example1') 
Example(_data=[(3,7),(145,31),(222.3,19),(370.5,19)]).save(formats=['pdf'],outDir='.',fnRoot='example2')0
-- 
Robin Becker
-------------- next part --------------
A non-text attachment was scrubbed...
Name: example.zip
Type: application/octet-stream
Size: 5672 bytes
Desc: not available
Url : http://two.pairlist.net/pipermail/reportlab-users/attachments/20051110/40d81e1e/example-0001.obj


More information about the reportlab-users mailing list