From: John H. <jdh...@ac...> - 2004-05-03 20:44:09
|
>>>>> "Engelsma," == Engelsma, Dave <D.Engelsma@LacksWheel.com> writes: Dave> Hello -- I'm having a dickens of a time getting this to Dave> work... I totally understand. A more extensive users guide is sorely needed. There is just so much to do on the development front that I haven't made time for it. Dave> I believe I understand what you mean about maintaining Dave> a list of FigureCanvasAggs and using string & bitmap Dave> methods to get the figures into my wxDialog. Dave> Where I'm stuck is in plotting a histogram to a Dave> FigureCanvasAgg... I've checked out your examples, but Dave> there doesn't appear to be anything that directly uses Dave> FigureCanvasAgg. I've tried many different ways (mostly Dave> based on the embedded_in_wx.py and histogram_demo.py Dave> examples). Dave> Based on the example "histogram_demo.py" could you Dave> please give some pointers as to how to plot the Dave> histogram to a FigureCanvasAgg? I think I can handle Dave> things after that... The example is included below. I'll add it to the examples dir for people who want to work directly with the Agg canvas and renderer. Let me know if you need some more help. Note that after you get the RGB string from Agg, you may want to destroy the figure and canvas if the figure is static to conserve memory. As repayment, if you have a nice screenshot showing your application in action, with the list box and figures etc, that I can include on the screenshots page, send it my way. from matplotlib.backends.backend_agg import FigureCanvasAgg from matplotlib.figure import Figure from matplotlib.axes import Subplot from matplotlib.mlab import normpdf from matplotlib.numerix import randn fig = Figure(figsize=(5,4), dpi=100) ax = Subplot(fig, 111) canvas = FigureCanvasAgg(fig) mu, sigma = 100, 15 x = mu + sigma*randn(10000) # the histogram of the data n, bins, patches = ax.hist(x, 50, normed=1) # add a 'best fit' line y = normpdf( bins, mu, sigma) line, = ax.plot(bins, y, 'r--') line.set_linewidth(1) ax.set_xlabel('Smarts') ax.set_ylabel('Probability') ax.set_title(r'$\rm{Histogram of IQ: }\mu=100, \sigma=15$') ax.set_xlim( (40, 160)) ax.set_ylim( (0, 0.03)) canvas.draw() s = canvas.tostring_rgb() # save this and convert to bitmap as needed |