FigureCanvasAgg.draw() very slow

I’m trying to figure out why this command is taking on average over 14 seconds to render a drawing of a fairly simple plot. If anyone has ideas, I’d really appreciate some help.

fig = figure(figsize=(12.5,3.75), dpi=80,facecolor = ‘y’, edgecolor=‘b’)

start_date = “20050710”
start_date += “T000000”
my_dates = list(rrule(DAILY, dtstart=parse(start_date), until=datetime.today()))
formatted_dates = [date2num(parse(start_date))]
for date in my_dates :
formatted_dates.append(date2num(date))
formatted_dates.append(date2num(datetime.today()))

y_ticks = []
for x in xrange(0,11):
my_string = str(x*10)+’ Percent’
y_ticks.append(my_string)

yticks(arange(0.0, 1.1, .1), y_ticks)

y_data = rand(len(formatted_dates))

ax = fig.add_subplot(111)
ax.plot_date(formatted_dates, y_data, ‘-’)

labels =
ax.get_xticklabels()
setp(labels, rotation=20, fontsize=8)
ax.autoscale_view()

#xlabel(’’)
#ylabel(’’)
title(‘Could put start date and end date here’)
grid(True)

canvas = FigureCanvasAgg(fig)

90% Run-time

···

############################################
############################################
canvas.draw()
############################################
############################################

imageSize = canvas.get_width_height()
imageRgb = canvas.tostring_rgb()
pilImage = Image.fromstring(“RGB”, imageSize, imageRgb)
pilImage.show()


Ready for the edge of your seat? Check out tonight’s top picks on Yahoo! TV.

I'm trying to figure out why this command is taking on average over 14
seconds to render a drawing of a fairly simple plot. If anyone has ideas,
I'd really appreciate some help.

fig = figure(figsize=(12.5,3.75), dpi=80,facecolor = 'y', edgecolor='b')

///snip

canvas = FigureCanvasAgg(fig)

You can't do this. You are combining pylab figure management (eg
figure) with explicit use of FigureCanvasAgg. Who the hell knows what
will happen.

If you want to use pylab, just create the figure as above and you can
access the cancas directly w/ fig.canvas and set your backend to Agg,
eg with

import matplotlib
matplotlib.use('Agg')

before importing pylab.

If you don't want to use pylab, follow the approach of

http://matplotlib.sf.net/examples/agg_oo.py

Note there we use matplotlib.figure.Figure to create the figure, not
pylab.figure.

This is probably your problem. If I were to guess, you are getting
caught up somewhere in some GUI nastiness inadvertently by using
pylab.figure and this is causing the slowdown.

JDH

···

On 7/10/07, Devin Halperin <dhalpuw@...9...> wrote: