Thanks for the hint, I now have:
        #figure is a matplotlib Figure
        #bitmap is a wx.StaticBitmap
        w_figure, h_figure = figure.get_size_inches()
        w_bitmap, h_bitmap = bitmap.GetSize()
        dpi = int(min(w_bitmap/w_figure,h_bitmap/h_figure))
        figure.set_dpi(dpi)
        figure.canvas.draw()
        w_canvas, h_canvas = figure.canvas.get_width_height()
        buffer = figure.canvas.tostring_rgb()
        bmp = wx.BitmapFromBuffer(w_canvas, h_canvas, buffer)
        bitmap.SetBitmap(bmp)
The size and dpi lines are meant to get a proper sizing of the canvas before
making a bitmap. This because I assume that the draw() converts vector
graphics to raster graphics. I am not sure all this is the cleverest way
but, when called from a wx.EVT_SIZE event it resizes nicely be it somewhat
slow.



Janwillem wrote:
> 
> I have an application where I would like to use show in a loop but as
> stated in 18.1 of the manual that does not work.
> # WARNING : illustrating how NOT to use show
> for i in range(10):
>     # make figure i
>     show()
> So I made a workaround in a custom wxDialog with a wxStaticBitmap and a
> few buttons and put the matplotlib figure in the bitmap with something
> like:
>         wi,hi = figure.get_size_inches()
>         width,height = bitmap_plot.GetSize()
>         dpi = int(min(width/wi,height/hi))
>         figure.savefig('/tmp/tmp.png',dpi = dpi)
>         image = wx.Image('/tmp/tmp.png',wx.BITMAP_TYPE_ANY)
>         bitmap = wx.BitmapFromImage(image)
>         bitmap_plot.SetBitmap(bitmap)
> Thus scaling the figure using the dpi option of savefig and then loading
> it into the wxStaticBitmap.
> 
> To me it seems there might be a lot of unnecessary data handling. What is
> the clever solution?
> mant thanks
> 

-- 
View this message in context: 
http://www.nabble.com/show-figures-in-a-loop-tp24776045p24779255.html
Sent from the matplotlib - users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to