~uhh-ssd/+junk/humidity_readout

« back to all changes in this revision

Viewing changes to plplot/plplot-5.9.9/examples/python/xw17.py

  • Committer: Joachim Erfle
  • Date: 2013-07-24 13:53:41 UTC
  • Revision ID: joachim.erfle@desy.de-20130724135341-1qojpp701zsn009p
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
# $Id: xw17.py 9904 2009-05-05 01:09:51Z airwin $
 
3
# Copyright 2002 Gary Bishop
 
4
# Copyright 2004 Alan W. Irwin
 
5
# This file is part of PLplot.
 
6
 
 
7
# PLplot is free software; you can redistribute it and/or modify
 
8
# it under the terms of the GNU Library General Public License as published by
 
9
# the Free Software Foundation; version 2 of the License.
 
10
 
 
11
# PLplot is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU Library General Public License for more details.
 
15
 
 
16
# You should have received a copy of the GNU Library General Public License
 
17
# along with the file PLplot; if not, write to the Free Software
 
18
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 
19
 
 
20
# Plots a simple stripchart with four pens.
 
21
 
 
22
# Append to effective python path so that can find plplot modules.
 
23
from plplot_python_start import *
 
24
 
 
25
import sys
 
26
from plplot_py_demos import *
 
27
 
 
28
# Parse and process command line arguments
 
29
plparseopts(sys.argv, PL_PARSE_FULL)
 
30
 
 
31
# Initialize plplot
 
32
plinit()
 
33
 
 
34
from time import sleep
 
35
 
 
36
def main():
 
37
    nsteps = 1000
 
38
    
 
39
# If db is used the plot is much more smooth. However, because of the
 
40
#   async X behaviour, one does not have a real-time scripcharter.
 
41
 
 
42
#    plsetopt("db", "")
 
43
#    plsetopt("np", "")
 
44
 
 
45
# User sets up plot completely except for window and data 
 
46
# Eventually settings in place when strip chart is created will be
 
47
# remembered so that multiple strip charts can be used simultaneously.
 
48
 
49
 
 
50
# Specify some reasonable defaults for ymin and ymax 
 
51
# The plot will grow automatically if needed (but not shrink) 
 
52
 
 
53
    ymin = -0.1
 
54
    ymax = 0.1
 
55
 
 
56
# Specify initial tmin and tmax -- this determines length of window. 
 
57
# Also specify maximum jump in t 
 
58
# This can accomodate adaptive timesteps 
 
59
 
 
60
    tmin = 0.
 
61
    tmax = 10.
 
62
    tjump = 0.3 # percentage of plot to jump 
 
63
 
 
64
# Axes options same as plbox. 
 
65
# Only automatic tick generation and label placement allowed 
 
66
# Eventually I ll make this fancier 
 
67
 
 
68
    colbox = 1
 
69
    collab = 3
 
70
    styline = [2, 3, 4, 5]
 
71
    colline = [2, 3, 4, 5]
 
72
 
 
73
    legline = ["sum", "sin", "sin*noi", "sin+noi"]
 
74
 
 
75
    xlab = 0.
 
76
    ylab = 0.25 # legend position 
 
77
 
 
78
    autoy = 1   # autoscale y 
 
79
    acc = 1     # don t scrip, accumulate 
 
80
 
 
81
    pladv(0)    
 
82
    plvsta()    
 
83
 
 
84
# Register our error variables with PLplot 
 
85
# From here on, we're handling all errors here 
 
86
 
 
87
    #plsError(&pl_errcode, errmsg)
 
88
 
 
89
    id1 = plstripc("bcnst", "bcnstv",
 
90
                   tmin, tmax, tjump, ymin, ymax,
 
91
                   xlab, ylab,
 
92
                   autoy, acc,
 
93
                   colbox, collab,
 
94
                   colline, styline, legline, 
 
95
                   "t", "", "Strip chart demo") 
 
96
 
 
97
# Let plplot handle errors from here on 
 
98
 
 
99
    #plsError(NULL, NULL)
 
100
 
 
101
    autoy = 0   # autoscale y 
 
102
    acc = 1     # accumulate 
 
103
 
 
104
# This is to represent a loop over time 
 
105
# Let's try a random walk process 
 
106
 
 
107
    y1 = y2 = y3 = y4 = 0.0
 
108
    dt = 0.1
 
109
 
 
110
    for n in range(nsteps):
 
111
        sleep(0.01)
 
112
        t = n * dt
 
113
        noise = plrandd() - 0.5
 
114
        y1 = y1 + noise
 
115
        y2 = sin(t*pi/18.)
 
116
        y3 = y2 * noise
 
117
        y4 = y2 + noise/3.
 
118
 
 
119
        # There is no need for all pens to have the same number of
 
120
        # points or beeing equally time spaced. 
 
121
                
 
122
        if n%2: 
 
123
            plstripa(id1, 0, t, y1)
 
124
        if n%3:
 
125
            plstripa(id1, 1, t, y2)
 
126
        if n%4:
 
127
            plstripa(id1, 2, t, y3)
 
128
        if n%5:
 
129
            plstripa(id1, 3, t, y4)
 
130
 
 
131
    # Destroy strip chart and it's memory 
 
132
 
 
133
    plstripd(id1)
 
134
    
 
135
    # No defaults changed so nothing to restore
 
136
 
 
137
main()
 
138
plend()