matplotlib server side with pdf backend

hi !

i would like to write a server side python script that generate .pdf documents.

for the moment i have Python 2.7 installed server side
and matplolib installed server side too.

A simple script that create a simple plot and generate a .png picture
works.

this is the script i use :

···

#-------------------------------------------

# to access standard output :

import sys

# select a non-GUI backend :

import matplotlib

matplotlib.use('Agg')
#matplotlib.use("cairo.pdf")

#matplotlib.use('PDF')

# import plotting module :

import matplotlib.pyplot as plt

# generate the plot :

plt.plot([1,2,3,2,3,4])

# print the content type (what's the data type)

# the new line is embedded, using '\n' notation :
print "Content-Type: image/png\n"
# print "Content-Type: image/PDF\n"
# print "Content-type: application/pdf"

# output directly to webserver, as a png file
  :
plt.savefig(sys.stdout, format='png')

# plt.savefig(sys.stdout, format='PDF')

# plt.savefig( "test.pdf", format='pdf' )

#-----------------------------------------------

I am wondering how to do the same thing but with sending a pdf file instead of
a png picture. (the # are for all the things i tried)

Does someone know ?

thanks.

jean-claude

The pdf backend rely on the "tell" method of a given file object,
which (I think) is not supported by stdout.
As a workaround, you may use StringIO.

from cStringIO import StringIO
outs = StringIO()
plt.savefig(outs, format='pdf')
print os.getvalue()

Regards,

-JJ

···

On Fri, Oct 1, 2010 at 8:59 PM, damiano michael <damiano-michael@...627...> wrote:

hi !

i would like to write a server side python script that generate .pdf
documents.

for the moment i have Python 2.7 installed server side
and matplolib installed server side too.

A simple script that create a simple plot and generate a .png picture
works.

this is the script i use :

#-------------------------------------------

# to access standard output :

import sys

# select a non-GUI backend :

import matplotlib

matplotlib.use('Agg')
#matplotlib.use("cairo.pdf")

#matplotlib.use('PDF')

# import plotting module :

import matplotlib.pyplot as plt

# generate the plot :

plt.plot([1,2,3,2,3,4])

# print the content type (what's the data type)

# the new line is embedded, using '\n' notation :
print "Content-Type: image/png\n"
# print "Content-Type: image/PDF\n"
# print "Content-type: application/pdf"

# output directly to webserver, as a png file
:
plt.savefig(sys.stdout, format='png')

# plt.savefig(sys.stdout, format='PDF')

# plt.savefig( "test.pdf", format='pdf' )

#-----------------------------------------------

I am wondering how to do the same thing but with sending a pdf file
instead of
a png picture. (the # are for all the things i tried)

Does someone know ?

thanks.

jean-claude

------------------------------------------------------------------------------
Virtualization is moving to the mainstream and overtaking non-virtualized
environment for deploying applications. Does it make network security
easier or more difficult to achieve? Read this whitepaper to separate the
two and get a better understanding.
http://p.sf.net/sfu/hp-phase2-d2d
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
matplotlib-users List Signup and Options