tutorial/PlotViewer: tutorial_plotviewer.py

File tutorial_plotviewer.py, 0.7 kB (added by andreas, 4 years ago)
Line 
1 viewer=gui.CreatePlotViewer()
2
3 data=gui.PlotData()
4
5 data.AddXY(1.0,0.0)
6 data.AddXY(1.5,0.23)
7 data.AddXY(2.0,0.45)
8 data.AddXY(3.2,0.79)
9 data.AddXY(4.0,0.61)
10 data.AddXY(5.1,0.52)
11 data.AddXY(7.0,0.33)
12 data.AddXY(8.0,0.41)
13
14 viewer.AddData(data).SetSymbolSize(5).SetMode(viewer.POINTS)
15
16 from math import sin
17
18 class sinc(gui.PlotFunction):
19   def __init__(self,width=1):
20     gui.PlotFunction.__init__(self)
21     self.width_=width
22   def Func(self,x):
23     if x==0:
24       return 1.0
25     else:
26       return sin(self.width_*x)/(self.width_*x)
27
28 sincinst=sinc()
29 viewer.AddData(sincinst).SetMode(viewer.LINES)
30
31 viewer.SetMinimumX(-10.0)
32 viewer.SetMaximumX(10.0)
33 viewer.SetMinimumY(-0.5)
34 viewer.SetMaximumY(1.5)