source: trunk/GSASIItestplot.py @ 5471

Last change on this file since 5471 was 5471, checked in by toby, 2 years ago

attempted fix: mpl does not always import .figure

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Author Revision URL Id
File size: 2.4 KB
Line 
1# -*- coding: utf-8 -*-
2#GSASIItestplot.py
3'''
4*GSASIItestplot: Plotting for testDeriv*
5========================================
6
7Plotting module used for script testDeriv.
8'''
9import wx
10import wx.aui
11import matplotlib as mpl
12import matplotlib.figure as mplfig
13try:
14    from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas
15except ImportError:
16    from matplotlib.backends.backend_wx import FigureCanvas as Canvas
17try:
18    from matplotlib.backends.backend_wxagg import NavigationToolbar2WxAgg as Toolbar
19except ImportError:
20    from matplotlib.backends.backend_wxagg import Toolbar as Toolbar # name changes in wx4.0.1
21
22class Plot(wx.Panel):
23    'Creates a plotting window'
24    def __init__(self, parent, id = -1, dpi = None, **kwargs):
25        wx.Panel.__init__(self, parent, id=id, **kwargs)
26        self.figure = mplfig.Figure(dpi=dpi, #figsize=(5,7)
27                                        )
28        self.canvas = Canvas(self, -1, self.figure)
29        self.toolbar = Toolbar(self.canvas)
30        self.toolbar.Realize()
31
32        sizer = wx.BoxSizer(wx.VERTICAL)
33        sizer.Add(self.canvas,1,wx.EXPAND)
34        sizer.Add(self.toolbar, 0 , wx.LEFT | wx.EXPAND)
35        self.SetSizer(sizer)
36
37class PlotNotebook(wx.Panel):
38    'creates a Wx application and a plotting notebook'
39    def __init__(self, id = -1):
40        self.app = wx.App()
41        self.frame = wx.Frame(None,-1,'Plotter', size=wx.Size(600,600),
42            style=wx.DEFAULT_FRAME_STYLE ^ wx.CLOSE_BOX)
43        self.status = self.frame.CreateStatusBar()
44        self.status.SetStatusText('Use K-box to set plot controls')
45        wx.Panel.__init__(self, self.frame, id=id)
46        self.nb = wx.aui.AuiNotebook(self,
47            style=wx.aui.AUI_NB_DEFAULT_STYLE ^ wx.aui.AUI_NB_CLOSE_ON_ACTIVE_TAB)
48        sizer = wx.BoxSizer()
49        sizer.Add(self.nb, 1, wx.EXPAND)
50        self.SetSizer(sizer)
51
52    def Show(self):
53        self.frame.Show()
54
55    def StartEventLoop(self):
56        self.Show()
57        self.app.MainLoop()
58
59    def add(self,name="plot"):
60       
61        def OnMotion(event):
62            xpos = event.xdata
63            if xpos:                                        #avoid out of frame mouse position
64                ypos = event.ydata
65                self.status.SetStatusText('X= %.3f Y= %.3f'%(xpos,ypos))
66               
67        page = Plot(self.nb)
68        page.canvas.mpl_connect('motion_notify_event', OnMotion)
69        self.nb.AddPage(page,name)
70        return page.figure
Note: See TracBrowser for help on using the repository browser.