Cat
plotter.py
Go to the documentation of this file.
1 import wx
2 import wx.aui
3 #import matplotlib as mpl
4 #import matplotlib.pyplot as plt
5 
6 
7 #from matplotlib.path import Path
8 #import matplotlib.patches as patches
9 
10 #import matplotlib as mpl
11 #mpl.use('WXAgg')
12 
13 #import matplotlib.backends.backend_wxagg as mwx
14 
15 #from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as Canvas
16 #from matplotlib.backends.backend_wxagg import NavigationToolbar2Wx as Toolbar
17 
18 import matplotlib.patches as patches
19 from matplotlib.path import Path
20 import matplotlib.pyplot as plt
21 import numpy as np
22 
23 
24 class plotter(wx.Panel):
25  def __init__(self, parent,figid):
26  if (parent==None):
27  self.figure = plt.figure(figid)
28  else:
29  wx.Panel.__init__(self, parent, id=-1)
30  self.figid = figid
31  self.figure = plt.figure(figid)
32  self.figure.subplots_adjust(top=0.9,bottom=0.05,right=0.95,left=0.05)
33  self.canvas = Canvas(self, -1, self.figure)
34  self.toolbar = Toolbar(self.canvas)
35  self.toolbar.Realize()
36  sizer = wx.BoxSizer(wx.VERTICAL)
37  sizer.Add(self.canvas,1,wx.EXPAND)
38  sizer.Add(self.toolbar, 0 , wx.LEFT | wx.EXPAND)
39  self.SetSizer(sizer)
40 
41  def current(self):
42  return self.figure
43 
44  def destroy(self):
45  self.canvas.Destroy()
46 
47 def h1d(fig, histo ,
48  alpha=0.5,
49  facecolor='green',
50  edgecolor='yellow',
51  linestyle='dashed'):
52  import numpy as np
53  left=np.array(histo.edges()[:-1])
54  right=np.array(histo.edges()[1:])
55  bottom = np.zeros(len(left))
56  top=bottom+histo.bins()
57  nrects=len(left)
58  nverts = nrects*(1+3+1)
59  verts = np.zeros((nverts, 2))
60  codes = np.ones(nverts, int) * Path.LINETO
61  codes[0::5] = Path.MOVETO
62  codes[4::5] = Path.CLOSEPOLY
63  verts[0::5,0] = left
64  verts[0::5,1] = bottom
65  verts[1::5,0] = left
66  verts[1::5,1] = top
67  verts[2::5,0] = right
68  verts[2::5,1] = top
69  verts[3::5,0] = right
70  verts[3::5,1] = bottom
71  barpath = Path(verts, codes)
72  patch = patches.PathPatch(barpath,
73  facecolor=facecolor,
74  edgecolor=edgecolor,
75  alpha=alpha,
76  linestyle=linestyle)
77  max=histo.maxY()
78  fig.add_patch(patch)
79  fig.set_xlim(histo.minX(), histo.maxX())
80  if (max>0):
81  fig.set_ylim(0.,max*1.05)
82  else:
83  fig.set_ylim(max*1.05,0.)
84 
87 
88 
89 
90 
91 
118 
119 
def __init__(self, parent, figid)
Definition: plotter.py:25
def h1d(fig, histo, alpha=0.5, facecolor='green', edgecolor='yellow', linestyle='dashed')
Definition: plotter.py:51
def current(self)
Definition: plotter.py:41
def destroy(self)
Definition: plotter.py:44