Adding watermark to canvas background

Hi Forum,

I am using matplotlib in a PyQt4 App.

I wanted to add a watermark-type pictures to the standard white background of the canvas.

My current version of this is :

def getwatermark(self):

factor=1.0 #factor for scaling image

im1=QtGui.QPixmap(’:/watermark.png’)

im=im1.toImage()

self.watermark_ratio=(im.height()/factor)/(im.width()/factor)

ival0=[]

for i in range(im.width()):#range(2): #range(im.width()):

for j in range(im.height()):#range(3): #range(im.height()):

if int(im.pixel(i,j))==0:

ival0.append(43)

else:

ival0.append(40)

self.watermark=reshape(ival0,(im.width(),im.height()))

def placewatermark(self,canvas,axes):

try:

if self.version==‘1’:

grayfactor=24 #factor for grayscale

canvassize=canvas.size()

if canvas.class.name==‘MyPFCanvas’:

#for PF, the IV canvas is split in two figures…

bottom=self.IVTab.IVcanvas.vert[0]._scalable_size

spacing=self.IVTab.IVcanvas.vert[1]._scalable_size

top=self.IVTab.IVcanvas.vert[2]._scalable_size

correctionY=top/(top+spacing+bottom)

else:

correctionY=1

origaxes=axes.axis()

xrange=origaxes[1]-origaxes[0]

yrange=origaxes[3]-origaxes[2]

xcanvas=canvassize.width()

ycanvas=canvassize.height()*correctionY

if (xcanvas/float(ycanvas))>self.watermark_ratio:

yfig=yrange

centery=origaxes[2]

xfig=self.watermark_ratio*yrange

xfig=(yfigself.watermark_ratio)(xrange/yrange)*(ycanvas/float(xcanvas))

centerx=origaxes[0]+(xrange-xfig)/2

else:

xfig=xrange

centerx=origaxes[0]

yfig=(xfig/self.watermark_ratio)*(yrange/xrange)/(ycanvas/float(xcanvas))

centery=origaxes[2]+(yrange-yfig)/2

axes.imshow(self.watermark,origin=‘lower’,extent=(centerx,centerx+xfig,centery,centery+yfig),vmin=0,vmax=43,cmap=cm.gray) #,extent=(centerx,centerx+xfig,centery,centery+yfig),

axes.axis(‘auto’)

axes.axis(origaxes)

canvas.draw()

except:

print “no watermark placeD”

pass

What is the best way to do this ?

Regards,

Dimitri

Does the following help?

http://matplotlib.sourceforge.net/search.html?q=codex+watermark

···

On Mon, Jan 25, 2010 at 8:14 AM, Dimitri Linten <dimitri.linten@...287...> wrote:

Hi Forum,
I am using matplotlib in a PyQt4 App.
I wanted to add a watermark-type pictures to the standard white background
of the canvas.

Dear John,

Thank you for your reply, however am looking for a watermark to be plotted inside the axis, not behind the axis

Regards,

Dimitri

···

On Mon, Jan 25, 2010 at 3:58 PM, John Hunter <jdh2358@…287…> wrote:

On Mon, Jan 25, 2010 at 8:14 AM, Dimitri Linten > > <dimitri.linten@…287…> wrote:

Hi Forum,

I am using matplotlib in a PyQt4 App.

I wanted to add a watermark-type pictures to the standard white background

of the canvas.

Does the following help?

http://matplotlib.sourceforge.net/search.html?q=codex+watermark

Please explain what you want and what your issue is.
Do not expect us (developers or other users) to study your code. If
possible, post a small stand-alone example that others can simply run.

As far as the watermark is concerned, the easiest way is to use
figimage as John suggested, but apparently this is not what you want.
The svn version of matplotlib has OffsetImage and AnnotationBox, which
could be helpful.

Regards,

-JJ

···

On Mon, Jan 25, 2010 at 9:14 AM, Dimitri Linten <dimitri.linten@...287...> wrote:

What is the best way to do this ?