简体   繁体   English

wxPython,wxformBuilder和matplotlib:将图形调整为面板大小

[英]wxPython, wxformBuilder and matplotlib: Resizing figure to panel

Hope you are able to help me with this. 希望你能帮助我。 - I'm new to both python and gui programming, so please bear with me. -我是python和gui编程的新手,所以请多多包涵。

I'm trying to create a simple GUI, using wxformBuilder, where the user can select a csv file and plot it in another panel (right_panel). 我正在尝试使用wxformBuilder创建一个简单的GUI,用户可以在其中选择一个csv文件并将其绘制在另一个面板中(right_panel)。 The GUI and structure can be seen in the following image: GUI and Structure 下图可以看到GUI和结构GUI和结构

I'm able to plot some sample data in the panel using the code shown below, but i can not get the figure to scale to the panel when resizing the window. 我可以使用下面显示的代码在面板中绘制一些示例数据,但是在调整窗口大小时,我无法将数字缩放到面板上。

import wx
import matplotlib
matplotlib.use('WXAgg')
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import \
    FigureCanvasWxAgg as FigureCanvas, \
    NavigationToolbar2WxAgg as NavigationToolbar
import numpy as np
import gui2


class explorerFrame(gui2.mainFrame):
    def __init__(self,parent): 
         gui2.mainFrame.__init__(self,parent) 
         self.CreatePlot()     
         return

     def CreatePlot(self):
         self.figure = Figure()           
         self.axes = self.figure.add_subplot(111)
         self.axes.grid()
         x = np.arange(0, 6, .01)
         y = np.sin(x**2)*np.exp(-x)
         self.axes.plot(x, y) 
         self.canvas = FigureCanvas(self.right_panel, -1, self.figure)

         return

 app = wx.App(False)
 frame = explorerFrame(None)
 frame.Show(True)
 app.MainLoop()

The following figures illustrates the scaling problem: Example 1 Example 2 下图说明了缩放问题: 示例1 示例2

I have tried adding a boxSizer inside the panel, but i'm unsure of how to place the canvas inside the sizer. 我尝试在面板内添加boxSizer,但是我不确定如何将画布放置在sizer中。 Any help would be greatly appreciated. 任何帮助将不胜感激。

Kind regards Kasper 亲切的问候卡斯珀

Sizers can certainly do the job. 大小确定者当然可以胜任。 With wxGlade I have included some matplotlib examples. 使用wxGlade,我提供了一些matplotlib示例。

This one should get you started on how to add a sizer to the panel: https://github.com/wxGlade/wxGlade/blob/master/examples/matplotlib/matplotlib_example.py 这应该让您开始如何在面板上添加缩放器: https : //github.com/wxGlade/wxGlade/blob/master/examples/matplotlib/matplotlib_example.py

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM