2013-11-21 41 views
1

我有同样的问题,如​​。
它有效,但这个数字不能覆盖整个框架;所以我改变了他的面板的大小和位置。现在的问题是,我的身材仍然和我的身材一样大,因此我只改变了面板尺寸,我的身材被“剪裁”了。我该如何解决这个问题?
为了更好地理解这个例子:我的框架是800x600,在这个框架内我的图形只有400x300的尺寸。嵌入matplotlib图并改变其大小

编辑:

import wx 
from numpy import arange, sin, pi 
import matplotlib 
#matplotlib.use('WXAgg') 

from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas 
from matplotlib.backends.backend_wx import NavigationToolbar2Wx 
from matplotlib.figure import Figure 

class MainFrame(wx.Frame): 
    def __init__(self): 
     wx.Frame.__init__(self, None, wx.ID_ANY, 
          "Pyramid App",size=(800,600),pos=((wx.DisplaySize()[0]-800)/2,(wx.DisplaySize()[1]-600)/2),style= wx.SYSTEM_MENU | wx.CAPTION | wx.MINIMIZE_BOX | wx.CLOSE_BOX) 

     self.PageThree = pageThree(self) 

class pageThree(wx.Panel): 
    def __init__(self, parent): 
     wx.Panel.__init__(self, parent=parent,size=(800,525)) 
     self.myparent=parent 
     self.pageThree=wx.Panel(self,size=(800,525)) # put some elements at this panel 
     self.pylabfigure = wx.Panel(self,size=(440,420),pos=(350,105)) # this is the panel for my figure 
     self.drawPylabFigure() 
     self.draw() 

    def drawPylabFigure(self): 
     self.figure = Figure() 
     self.axes = self.figure.add_subplot(111) 
     self.canvas = FigureCanvas(self.pylabfigure, -1, self.figure) 
     self.sizer = wx.BoxSizer(wx.VERTICAL) 
     self.sizer.Add(self.canvas, 1, wx.LEFT | wx.TOP | wx.GROW) 
     self.SetSizer(self.sizer) 
     self.Fit() 

    def draw(self): 
     #example drawing 
     t = arange(0.0, 3.0, 0.01) 
     s = sin(2 * pi * t) 
     self.axes.plot(t, s) 

if __name__ == "__main__": 
    app = wx.App() 
    MainFrame().Show() 
    app.MainLoop() 
+0

pls.show一些代码 – joaquin

+0

对不起,我编辑。 – Munchkin

回答

1

这会给你一个如何去做的想法。 重要的是要考虑它把你的面板/帆布由一个sizer组织。另外,如果画布必须填满他的身体,则不需要将其放在面板中。

import wx 
from numpy import arange, sin, pi 
import matplotlib 
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FCW 
from matplotlib.figure import Figure 

class MainFrame(wx.Frame): 
    def __init__(self): 
     wx.Frame.__init__(self, None, wx.ID_ANY, 
          "Pyramid App",size=(800,600), 
          pos=((wx.DisplaySize()[0]-800)/2,(wx.DisplaySize()[1]-600)/2), 
          style=wx.SYSTEM_MENU | wx.CAPTION | wx.MINIMIZE_BOX | wx.CLOSE_BOX) 

     self.PageThree = pageThree(self) 

class pageThree(wx.Panel): 
    def __init__(self, parent): 
     wx.Panel.__init__(self, parent=parent,size=(800,525)) 
     self.myparent=parent 
     self.pageThree=wx.Panel(self, size=(500,525)) 
     self.drawPyFigure() 
     self.draw() 

    def drawPyFigure(self): 
     self.figure = Figure() 
     self.axes = self.figure.add_subplot(111) 
     self.canvas = FCW(self, -1, self.figure) 
     sizer = wx.BoxSizer(wx.HORIZONTAL) 
     sizer.Add(self.pageThree, 0) 
     sizer.Add(self.canvas, 1, wx.EXPAND) 
     self.SetSizer(sizer) 
     self.Fit() 

    def draw(self): 
     t = arange(0.0, 3.0, 0.01) 
     s = sin(2 * pi * t) 
     self.axes.plot(t, s) 

if __name__ == "__main__": 
    app = wx.App() 
    MainFrame().Show() 
    app.MainLoop() 

enter image description here

0

简而言之,你要self.figure = Figure(figsize=(400/80.0, 300/80.0))

您需要指定图形的大小(默认为8英寸宽×6英寸高)和/或图形的dpi(默认为80,用于屏幕显示)。

但是,请注意,图屏幕上的图的大小仅取决于像素的总数(换句话说,即width_inches*dpi x height_inches*dpi)。因此,如果我们想要一个数字是一个特定数量的像素,我们需要将其转换为“英寸”(如果它显示在屏幕上,则与数字的显示大小无关)由图的dpi。

+0

你测试过了吗?当我更改这条线时,没有任何变化。我用几个参数对它进行了测试,但是我的图像看起来总是一样的。 – Munchkin