wxPython - 在 ScrolledPanel 中调整 MatPlotLib FigureCanvas 的大小
我在面板的 ScrolledPanel 中有一个图形画布。我想改变图形画布的大小。例如
mplFigure.set_figheight(1.0)
someobject.soSomethingThatResizeItAll
我该怎么做?
谢谢
大卫
这是我的构建代码。
panel = wx.Panel(self) # we put the scrollablePanel in the panel so later on we can do fit to window sizing too (i.e. by removing the scrollablePanel)
# create a scrollablePanel to hold the canvas
scrollablePanel = ScrolledPanel(parent=panel, id=wx.ID_ANY, name="scrolledPanel", style=wx.ALWAYS_SHOW_SB)
scrollablePanel.SetupScrolling()
scrollablePanel.SetBackgroundColour(wx.Colour(128,128,128))
# create mpl canvas and figure
mplFigure = Figure(figsize=A6H, facecolor="white") #, edgecolor="black")
mplFigureCanvas = FigureCanvasWxAgg(parent=scrollablePanel, id=wx.ID_ANY, figure=mplFigure)
#mplFigureCanvas.SetWindowStyle=wx.SIMPLE_BORDER # not sure if this will have any affect?
#mplFigureCanvas.SetBackgroundColour(wx.Colour(0,0,0))
# center the FigureCanvas inthe scrollablePanel
sizer1 = wx.BoxSizer(wx.VERTICAL)
sizer1.Add(mplFigureCanvas, proportion=0, flag=wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, border=8)
sizer2 = wx.BoxSizer(wx.HORIZONTAL)
sizer2.Add(sizer1, proportion=1, flag=wx.ALIGN_CENTER_VERTICAL)
scrollablePanel.SetSizer(sizer2)
# create mpl toolbar
#mplToolbar = NavigationToolbar2Wx(mplFigureCanvas)
#mplToolbar.Realize() # needed to support Windows systems
# use another sizer to add the scrollablePanel to the main panel
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(scrollablePanel, 1, wx.LEFT | wx.EXPAND)
#sizer.Add(mplToolbar, 0, wx.LEFT | wx.EXPAND)
#mplToolbar.Show()
panel.SetSizer(sizer)
I have a figure canvas in a ScrolledPanel in a Panel. I want to change the size of the figure canvas. E.g.
mplFigure.set_figheight(1.0)
someobject.soSomethingThatResizeItAll
How can I do this?
Thanks
David
Here's my construction code.
panel = wx.Panel(self) # we put the scrollablePanel in the panel so later on we can do fit to window sizing too (i.e. by removing the scrollablePanel)
# create a scrollablePanel to hold the canvas
scrollablePanel = ScrolledPanel(parent=panel, id=wx.ID_ANY, name="scrolledPanel", style=wx.ALWAYS_SHOW_SB)
scrollablePanel.SetupScrolling()
scrollablePanel.SetBackgroundColour(wx.Colour(128,128,128))
# create mpl canvas and figure
mplFigure = Figure(figsize=A6H, facecolor="white") #, edgecolor="black")
mplFigureCanvas = FigureCanvasWxAgg(parent=scrollablePanel, id=wx.ID_ANY, figure=mplFigure)
#mplFigureCanvas.SetWindowStyle=wx.SIMPLE_BORDER # not sure if this will have any affect?
#mplFigureCanvas.SetBackgroundColour(wx.Colour(0,0,0))
# center the FigureCanvas inthe scrollablePanel
sizer1 = wx.BoxSizer(wx.VERTICAL)
sizer1.Add(mplFigureCanvas, proportion=0, flag=wx.ALL|wx.ALIGN_CENTER_HORIZONTAL, border=8)
sizer2 = wx.BoxSizer(wx.HORIZONTAL)
sizer2.Add(sizer1, proportion=1, flag=wx.ALIGN_CENTER_VERTICAL)
scrollablePanel.SetSizer(sizer2)
# create mpl toolbar
#mplToolbar = NavigationToolbar2Wx(mplFigureCanvas)
#mplToolbar.Realize() # needed to support Windows systems
# use another sizer to add the scrollablePanel to the main panel
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(scrollablePanel, 1, wx.LEFT | wx.EXPAND)
#sizer.Add(mplToolbar, 0, wx.LEFT | wx.EXPAND)
#mplToolbar.Show()
panel.SetSizer(sizer)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好吧,我现在有一些可怕的代码可以得到结果,但它并不漂亮。
如有改进将受到欢迎。
——数据库
Well I now have some horrible code that gets the result but it's not pretty.
An improvement would be welcome.
-- DB
好吧,我已经找到了部分答案。
mplFigureCanvas.SetSize(...) 最初会执行此操作,但一旦我调整框架大小,它就会恢复到原始大小。
——数据库
Well I've found part of the answer.
mplFigureCanvas.SetSize(...)
does it initially but as soon as I resize the frame it goes back to the original size.-- DB
如果我正确理解你的问题,我想你会想要以不同的方式设置你的面板。我会将
mpl_canvas
放入wx.Panel
中,然后将该面板放入ScrolledPanel
中。然后,要放大/缩小画布,只需更新面板的MinSize
(panel.SetMinSize()
)。If I understand your question correctly I think you'll want to set up your panels differently. I would put the
mpl_canvas
in awx.Panel
and then put that panel into theScrolledPanel
. Then to enlarge/shrink the canvas just update theMinSize
of the panel (panel.SetMinSize()
).