matplotlib and Zope

Message

For importing External Method in Zope, what is the module to
import?

Create a file (e.g. mpl.py) in INSTANCEHOME\Extensions.

------ mpl.py: ---------------------
from pylab import *
from os import *
from StringIO import StringIO
from PIL import Image as PILImage
from matplotlib.backends.backend_agg import FigureCanvasAgg

def chart(self):
clf()
dpi=72
width=400
height=300
fig=figure(dpi, figsize=(width/dpi, height/dpi))
#ax=subplot(111)
x=arange(0, 2*pi+0.1, 0.1)
sine=plot(x, sin(x))
legend(sine, “y=sin x”, “upper right”)
xlabel(‘x’)
ylabel(‘y=sin x’)
grid(True)
canvas = FigureCanvasAgg(fig)
canvas.draw()
size = canvas.get_width_height()
buf=canvas.tostring_rgb()
im=PILImage.fromstring(‘RGB’, size, buf, ‘raw’, ‘RGB’, 0, 1)
imgdata=StringIO()
im.save(imgdata, ‘PNG’)
self.REQUEST.RESPONSE.setHeader(‘Pragma’, ‘no-cache’)
self.REQUEST.RESPONSE.setHeader(‘Content-Type’, ‘image/png’)
return imgdata.getvalue()

···

Then create an external method in ZMI (e.g. Id → mplchart, module name →
mpl, function name → chart).

matplotlib or pylab Do you also have to import numeric python first?

If you import pylab, then there is no need to import Numeric.

I need a real world example not a ‘foo.py’ module.

See above.

Regards,
Sascha