2013-04-10 2 views
1

이 python 프로그램은 wxpython 창에서 그림을 그립니다.wxpython + matplotlib : matplotlib 그림 자동 크기 지정

어떻게 프로그램을 변경할 수 있습니다 그래서 :

  • 내가 메인 윈도우는 특정의 크기보다 작은 크기를 조정할 수 없습니다
  • 창을 크기를 조정할 때 그림의 크기를 조정? (예 : 창 크기의 절반)

.

# adapted from: 
# http://wiki.wxpython.org/Getting%20Started 
# http://www.cs.colorado.edu/~kena/classes/5448/s11/presentations/pearse.pdf 

import wx 
import pylab as pl 
import matplotlib 
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas 

class GUIPanel(wx.Panel): 
    def __init__(self, parent): 
     wx.Panel.__init__(self, parent) 
     self.parent = parent 

     # create some sizers 
     sizer = wx.BoxSizer(wx.VERTICAL) 

     # A button 
     self.button =wx.Button(self, label="Tada!") 
     self.Bind(wx.EVT_BUTTON, self.OnClick,self.button) 

     # put up a figure 
     self.figure = pl.figure() 
     self.axes = self.drawplot(self.figure) 
     self.canvas = FigureCanvas(self, -1, self.figure) 

     sizer.Add(self.canvas, 0, wx.ALIGN_CENTER|wx.ALL) 
     sizer.Add(self.button, 0, wx.ALIGN_CENTER|wx.ALL) 

     self.SetSizerAndFit(sizer) 
    def log(self, fmt, *args): 
     print (fmt % args) 
    def OnClick(self,event): 
     self.log("button clicked, id#%d\n", event.GetId()) 
    def drawplot(self, fig): 
     ax = fig.add_subplot(1,1,1) 
     t = pl.arange(0,1,0.001) 
     ax.plot(t,t*t) 
     ax.grid() 
     return ax 

app = wx.App(False) 
frame = wx.Frame(None) 
panel = GUIPanel(frame) 
frame.Fit() 
frame.Center() 
frame.Show() 
app.MainLoop() 
+0

은 다른 질문의 빛이 변화합니까? – tacaswell

+0

번. [쓸데없는 비의 소리는 글자를 채우기 위해] –

답변

2

1)이가는 길 당신 설치하여 선별기를 수정 : 여기

sizer.Add(self.canvas, 1, wx.EXPAND | wx.ALL) 

method reference입니다. wxPython Demo을 설치하여 사용하는 것도 도움이됩니다. Sizer는 거기에서 잘 덮여 있습니다. 당신이 국경을 지정하지 않으면 BTW : wx.ALL 쓸모가있다.


2) 그리고 frame.Show() 후 프레임 설정이 추가 :

size = frame.GetSize() 
frame.SetMinSize((size[0]/2, size[1]/2))