Hi Stan,
this size problem sounds somewhat familiar to me. I had a serious
headache to get the interaction of wx.ScrolledWindow, wx.BoxSizer and
matplotlib.backends.backend_wxagg.FigureCanvasWxAgg right when zooming a
canvas in and out and resizing the window.

I am not sure if it will help you, but I've attached how exactly I set
up the three elements to behave as I wish. Unrelated code is stripped
from the example.

Hope that helps!

Dieter


Am Montag, den 15.08.2011, 13:30 -0400 schrieb Stan West:
>         From: Stan West [mailto:stan.w...@nrl.navy.mil] 
>         Sent: Monday, August 15, 2011 13:21
>         
>                 From: David Just [mailto:just.da...@mayo.edu] 
>                 Sent: Friday, August 12, 2011 11:05
>                  
>                 
>                 Now that I’m pre-building all my enlarged interpolated
>                 images to scroll through,  I’m having trouble forcing
>                 the figure/FigureCanvas to be the size I want.
>                 
>                 I’m trying: 
>                 fig.set_size_inches(768 / 72.0, 768 / 72.0),  but it
>                 ends up the same size as the default plot.
>         
>         If the issue is that the GUI window is not changing size, try
>         adding "forward=True" to the set_size_inches call. 
>         
> Developers:
> 
> As I was checking this with v. 1.0.1, I noticed that the Qt4Agg and
> TkAgg backends are inconsistent in how they set the size of a figure.
> Here is the Qt4Agg behavior:
> 
>         >>> fig = plt.figure(figsize=[6, 4])
>         >>> print fig.get_size_inches()
>         [ 6.          3.97916667]
>         >>> fig.set_size_inches([6, 4], forward=True)
>         >>> print fig.get_size_inches()
>         [ 6.      3.4375]
> 
> The initial figure size isn't quite right, and the size after
> set_size_inches is worse. (Is the resize ignoring the toolbar height?)
> Here is the TkAgg behavior:
> 
>         >>> fig = plt.figure(figsize=[6, 4])
>         >>> print fig.get_size_inches()
>         [ 6.125  4.125]
>         >>> fig.set_size_inches([6, 4], forward=True)
>         >>> print fig.get_size_inches()
>         [ 6.          3.64583333]
> 
> Again, the initial size is off (due to the window border?), and the
> resized size is incorrect (toolbar again?).
> 
> The WXAgg backend correctly sets the figure canvas to the desired
> size:
> 
>         >>> fig = plt.figure(figsize=[6, 4])
>         >>> print fig.get_size_inches()
>         [ 6.  4.]
>         >>> fig.set_size_inches([6, 4], forward=True)
>         >>> print fig.get_size_inches()
>         [ 6.  4.]
> 
> I didn't check any other backends.
> 
> I didn't see any indication in the master branch that this behavior
> has changed since 1.0.1. I didn't find a report for this issue on the
> tracker; shall I create one?
> 
> 
> ------------------------------------------------------------------------------
> uberSVN's rich system and user administration capabilities and model 
> configuration take the hassle out of deploying and managing Subversion and 
> the tools developers use with it. Learn more about uberSVN and get a free 
> download at:  http://p.sf.net/sfu/wandisco-dev2dev
> _______________________________________________
> Matplotlib-devel mailing list
> Matplotlib-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

# -*- coding: utf-8 -*-
import wx
import matplotlib
matplotlib.use('WXAgg')
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure

class PlotReport(wx.NotebookPage):
    def __init__(self, *args, **kwargs):
        super(PlotReport, self).__init__(*args, style=wx.VSCROLL|wx.HSCROLL, **kwargs)
        self.figure = Figure()
        self.scrollarea = wx.ScrolledWindow(parent=self, style=wx.VSCROLL|wx.HSCROLL)
        self.canvas = FigureCanvas(parent=self.scrollarea, id=wx.ID_ANY, figure=self.figure)
        self.sizer = wx.BoxSizer(orient=wx.VERTICAL)
        self.sizer.Add(item=self.canvas, proportion=1, flag=wx.EXPAND|wx.ALIGN_CENTER)
        self.scrollarea.SetSizer(self.sizer)
        self.set_good_scrollrate()
        self.Bind(wx.EVT_SIZE, self.onSize)
        self.canvas.Bind(wx.EVT_CHAR, self.onPlotChar)

    def set_good_scrollrate(self):
        size = self.scrollarea.GetVirtualSize()
        self.scrollarea.SetScrollRate(size.GetWidth()/50, size.GetHeight()/50)

    # zooming in and out with Ctrl-+ and Ctrl--
    def onPlotChar(self, evt):
        code = evt.GetKeyCode()
        if evt.ControlDown() and code < 256:
            if chr(code) == '+':
                size = self.canvas.GetSize()
                size.Scale(1.3, 1.3)
                availSize = self.scrollarea.GetSize()
                minw = max(size.GetWidth(), availSize.GetWidth())
                minh = max(size.GetHeight(), availSize.GetHeight())
                self.canvas.SetMinSize(wx.Size(minw, minh))
                self.canvas.SetMaxSize(wx.DefaultSize)
                self.sizer.SetVirtualSizeHints(self.scrollarea)
                self.set_good_scrollrate()
            elif chr(code) == '-':
                size = self.canvas.GetSize()
                size.Scale(1/1.3, 1/1.3)
                self.canvas.SetMinSize(size)
                self.canvas.SetMaxSize(wx.DefaultSize)
                self.scrollarea.SetVirtualSizeHintsSz(wx.DefaultSize, size)
                self.sizer.SetVirtualSizeHints(self.scrollarea)
                self.set_good_scrollrate()
            else:
                evt.Skip()
        else:
            evt.Skip()

    def onSize(self, evt):
        self.set_good_scrollrate()
        evt.Skip()
------------------------------------------------------------------------------
uberSVN's rich system and user administration capabilities and model 
configuration take the hassle out of deploying and managing Subversion and 
the tools developers use with it. Learn more about uberSVN and get a free 
download at:  http://p.sf.net/sfu/wandisco-dev2dev
_______________________________________________
Matplotlib-devel mailing list
Matplotlib-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-devel

Reply via email to