-
-
Save bheklilr/a994fd95daad5c12c853 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import unicode_literals | |
import wx | |
import matplotlib as mpl | |
mpl.use("WXAgg") | |
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas | |
from matplotlib.figure import Figure | |
class GraphTab(wx.Frame): | |
def __init__(self, parent, wxId, numGraphs): | |
wx.Frame.__init__(self, parent=parent, id=wxId) | |
self.__buildLayout(numGraphs) | |
def __buildLayout(self, numGraphs): | |
self.sizer = wx.BoxSizer(wx.VERTICAL) | |
self.fig = Figure() | |
self.canvas = FigureCanvas(self, -1, self.fig) | |
if numGraphs == 1: | |
self.ax1 = self.fig.add_subplot(1, 1, 1) | |
elif numGraphs == 2: | |
self.ax1 = self.fig.add_subplot(1, 2, 1) | |
self.ax2 = self.fig.add_subplot(1, 2, 2) | |
elif numGraphs == 3: | |
self.ax1 = self.fig.add_subplot(1, 2, 1) | |
self.ax2 = self.fig.add_subplot(2, 2, 2) | |
self.ax3 = self.fig.add_subplot(2, 2, 4) | |
elif numGraphs == 4: | |
self.ax1 = self.fig.add_subplot(2, 2, 1) | |
self.ax2 = self.fig.add_subplot(2, 2, 2) | |
self.ax3 = self.fig.add_subplot(2, 2, 3) | |
self.ax4 = self.fig.add_subplot(2, 2, 4) | |
self.sizer.Add(self.canvas, 1, wx.EXPAND) | |
self.SetSizer(self.sizer) | |
class Test(wx.Frame): | |
def __init__(self, parent=None): | |
wx.Frame.__init__(self, parent) | |
sizer = wx.BoxSizer(wx.VERTICAL) | |
panel = wx.Panel(self) | |
nb = wx.Notebook(panel) | |
gt1 = GraphTab(self, -1, 1) | |
gt1.ax1.plot([1, 2, 3], [2, 3, 1]) | |
gt2 = GraphTab(nb, -1, 2) | |
gt3 = GraphTab(nb, -1, 3) | |
gt4 = GraphTab(nb, -1, 4) | |
nb.AddPage(gt1, "Test1") | |
nb.AddPage(gt2, "Test2") | |
nb.AddPage(gt3, "Test3") | |
nb.AddPage(gt4, "Test4") | |
sizer.Add(nb, 1, wx.EXPAND) | |
panel.SetSizerAndFit(sizer) | |
if __name__ == '__main__': | |
app = wx.App(redirect=False) | |
gui = Test() | |
gui.Show() | |
app.MainLoop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment