Dear all,

I want to generate a pdf with some text and graphics. Since I use
matplotlib to make plot through the graphical user interface, I want to
embed these graphs directly into a cairo (or pangocairo) instance.

But I cannot manage.

I send a small example. If you can help me....

import cairo
import pango
import pangocairo
import matplotlib
matplotlib.use('Cairo')
from matplotlib import pyplot

surface = cairo.PDFSurface('test_report.pdf', 595, 795)
context = pangocairo.CairoContext(cairo.Context(surface))

context.translate(0, 50)
layout = context.create_layout()
layout.set_text('Hello, this is a long text to see if the lines are
automatically broken.')
layout.set_font_description(pango.FontDescription("Sans Bold 12"))
layout.set_width(pango.SCALE * 570)
# Put the text in the context.
context.set_source_rgb(0, 0, 0)
context.show_layout(layout)

figure = pyplot.figure()
axe = figure.add_subplot(111)
toto = axe.plot(range(20),[i**2 for i in range(20)])
context.set_source(figure.canvas)

Thanks a lot.


------------------------------------------------------------------------------
The modern datacenter depends on network connectivity to access resources
and provide services. The best practices for maximizing a physical server's
connectivity to a physical network are well understood - see how these
rules translate into the virtual world? 
http://p.sf.net/sfu/oracle-sfdevnlfb
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to