I'd like plot a figure(having many subfigures) in a scrolledwindow(or scrolledpanel).
figure width depends on the width of window and figure height is calculated like width * 2.
if the height of window ls less than width * 2, scrollbar of window is enabled.
with the following code, I checked the size of figure, canvas and window.
the height of figure and figure is bigger than the height of window. but scrollbar is not enabled.
I tried with boxsizer also, but it did not work.
Can you make this code work?
from matplotlib.backends.backend_wxagg import \
FigureCanvasWxAgg as FigureCanvas, \
NavigationToolbar2WxAgg as NavigationToolbar
from matplotlib.figure import Figure
import numpy as np
import wx
from wx.lib.scrolledpanel import ScrolledPanel
class MyFrame(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, id=wx.ID_ANY, title=title,
pos=wx.DefaultPosition, size=wx.Size(200, 300))
# self.T_panel = wx.Panel(self)
# self.T_wd = wx.ScrolledWindow(self.T_panel, -1, wx.DefaultPosition,
# wx.DefaultSize, wx.VSCROLL|wx.ALWAYS_SHOW_SB)
self.T_wd = ScrolledPanel(self, -1, size=wx.Size(200, 300))
self.Bind(wx.EVT_SIZE, self.onSize)
self.T_wd.SetupScrolling()
self.T_fig = Figure((5.0,5.0), dpi=80)
self.T_canvas = FigureCanvas(self.T_wd, -1, self.T_fig)
self.graph = self.T_fig.add_subplot(111)
self.T_wd.Layout()
def onSize(self, event):
size = event.GetSize()
x = np.arange(5)
y = np.random.rand(5) * 5.
self.T_fig.set_size_inches(size[0]/80., size[0]/40.)
self.T_canvas.SetSize((size[0], size[0]*2))
self.graph.hold(False)
self.graph.plot(x,y)
self.T_canvas.draw()
self.T_wd.SetSize(size)
self.T_wd.SetupScrolling()
print 'event size', size
print 'fig size', self.T_fig.get_size_inches()*80
print 'canvas size', self.T_canvas.GetSize()
print 'window(panel) wize', self.T_wd.GetSize()
print ''
class my_App(wx.App):
def OnInit(self):
frame = MyFrame(None, title = 'test')
frame.Show(True)
self.SetTopWindow(frame)
return True
my_App().MainLoop()