Hope you are able to help me with this. - I'm new to both python and gui programming, so please bear with me.
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). The GUI and structure can be seen in the following image: GUI and Structure
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
I have tried adding a boxSizer inside the panel, but i'm unsure of how to place the canvas inside the sizer. Any help would be greatly appreciated.
Kind regards Kasper
Sizers can certainly do the job. With wxGlade I have included some matplotlib examples.
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