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=(yfig*self.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
------------------------------------------------------------------------------
Throughout its 18-year history, RSA Conference consistently attracts the
world's best and brightest in the field, creating opportunities for Conference
attendees to learn about information security's most important issues through
interactions with peers, luminaries and emerging and established companies.
http://p.sf.net/sfu/rsaconf-dev2dev
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to