FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Random/plotting/gnuplot.py at master · avaitla/Random · GitHub
avaitla
/
Random
Public
Notifications
You must be signed in to change notification settings
Fork
2
Star
2
Code
Issues
0
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
Random
/
plotting
/
gnuplot.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
127 lines (96 loc) · 4.39 KB
Breadcrumbs
Random
/
plotting
/
gnuplot.py
Copy path
File metadata and controls
127 lines (96 loc) · 4.39 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#Python Port of http://users.softlab.ntua.gr/~ttsiod/gnuplotStreaming.html
import
os
,
sys
,
time
from
subprocess
import
Popen
,
PIPE
def
get_args
():
params
=
{
"NumberOfStreams"
:
0
,
"NumberOfWindows"
:
0
,
"Window_Sample_Sizes"
: [],
"Window_Y_Ranges"
: [],
"Window_Geometries"
: [],
"Stream_Titles"
: [],
"Stream_Window_Number"
: [],
"Stream_Buffers"
: []}
usage
=
'''
\n
Usage: NumberOfStreams ( M ) NumberOfWindows ( N )
Window_0_WindowSampleSize < ... Window_N_WindowSampleSize >
Window_0_YRangeMin Window_0_YRangeMax < ... Window_N_YRangeMin Window_N_YRangeMax >
Window_0_Geometry < ... Window_N_Geometry > ( WidthxHeight+XOFF+YOFF )
Stream_0_Title < ... Stream_M_Title >
Stream_0_Window_Number < ... Stream_M_Window_Number >
\n
'''
try
:
_filename
=
sys
.
argv
.
pop
(
0
)
params
[
"NumberOfStreams"
]
=
int
(
sys
.
argv
.
pop
(
0
))
params
[
"NumberOfWindows"
]
=
int
(
sys
.
argv
.
pop
(
0
))
for
i
in
range
(
params
[
"NumberOfWindows"
]):
params
[
"Window_Sample_Sizes"
].
append
(
int
(
sys
.
argv
.
pop
(
0
)))
for
i
in
range
(
params
[
"NumberOfWindows"
]):
params
[
"Window_Y_Ranges"
].
append
((
int
(
sys
.
argv
.
pop
(
0
)),
int
(
sys
.
argv
.
pop
(
0
))))
for
i
in
range
(
params
[
"NumberOfWindows"
]):
params
[
"Window_Geometries"
].
append
(
sys
.
argv
.
pop
(
0
))
for
i
in
range
(
params
[
"NumberOfStreams"
]):
params
[
"Stream_Titles"
].
append
(
sys
.
argv
.
pop
(
0
))
params
[
"Stream_Buffers"
].
append
([])
for
i
in
range
(
params
[
"NumberOfStreams"
]):
params
[
"Stream_Window_Number"
].
append
(
int
(
sys
.
argv
.
pop
(
0
)))
except
Exception
:
print
usage
sys
.
exit
(
1
)
return
params
def
main
():
params
=
get_args
()
numberOfStreams
=
params
[
"NumberOfStreams"
]
numberOfWindows
=
params
[
"NumberOfWindows"
]
sampleSizes
=
params
[
"Window_Sample_Sizes"
]
ranges
=
params
[
"Window_Y_Ranges"
]
geometries
=
params
[
"Window_Geometries"
]
titles
=
params
[
"Stream_Titles"
]
windows
=
[
params
[
"Stream_Window_Number"
][
i
]
for
i
in
range
(
numberOfStreams
)]
streams
=
dict
([(
i
, [])
for
i
in
range
(
numberOfWindows
)])
print
params
[
"Stream_Window_Number"
]
for
i
,
item
in
enumerate
(
params
[
"Stream_Window_Number"
]):
streams
[
item
].
append
(
i
)
gnuplots
=
[]
buffers
=
[[]]
*
numberOfStreams
xcounters
=
[
0
]
*
numberOfStreams
for
window
in
range
(
params
[
"NumberOfWindows"
]):
print
geometries
fd
=
Popen
((
"gnuplot -geometry %s"
%
geometries
[
window
]),
shell
=
True
,
stdin
=
PIPE
).
stdin
gnuplots
.
append
(
fd
)
print
>>
fd
,
"set xtics"
print
>>
fd
,
"set ytics"
yrange
=
params
[
"Window_Y_Ranges"
][
window
]
print
>>
fd
,
"set yrange [%d:%d]"
%
(
yrange
[
0
],
yrange
[
1
])
print
>>
fd
,
"set style data linespoints"
print
>>
fd
,
"set grid"
print
>>
fd
,
"set term x11"
while
True
:
inp
=
raw_input
()
_stream
,
_value
=
inp
.
split
(
":"
)
streamIdx
=
int
(
_stream
)
windowIdx
=
windows
[
streamIdx
]
pip
=
gnuplots
[
windowIdx
]
xcounter
=
xcounters
[
streamIdx
]
buffers
[
streamIdx
]
=
buffers
[
streamIdx
]
+
[
str
(
xcounter
)
+
" "
+
str
(
_value
)]
xcounters
[
streamIdx
]
+=
1
max_xcounter
=
xcounter
for
stream
in
streams
[
windowIdx
]:
if
(
xcounters
[
stream
]
>
max_xcounter
):
max_xcounter
=
xcounters
[
stream
]
print
>>
pip
,
" set xrange ["
+
str
(
max_xcounter
-
sampleSizes
[
windowIdx
])
+
":"
+
str
(
max_xcounter
)
+
"]"
plots
=
[]
for
stream
in
streams
[
windowIdx
]:
if
(
len
(
buffers
[
stream
])
>
0
):
plots
.
append
(
"
\"
-
\"
title '%s'"
%
titles
[
stream
])
print
>>
pip
,
"plot "
+
(
", "
.
join
(
plots
))
for
stream
in
streams
[
windowIdx
]:
if
(
len
(
buffers
[
stream
])
>
0
):
for
elem
in
buffers
[
stream
][::
-
1
]:
print
>>
pip
, (
"%s"
%
elem
)
print
>>
pip
,
"e"
if
(
len
(
buffers
[
streamIdx
])
>
sampleSizes
[
windowIdx
]):
buffers
[
streamIdx
]
=
buffers
[
streamIdx
][
1
:]
pip
.
flush
()
for
i
in
range
(
numberOfWindows
):
pip
=
gnuplots
[
i
]
print
>>
pip
,
"exit;"
pip
.
flush
()
# Let's assuming we are streaming from stdin
if
__name__
==
"__main__"
:
main
()
Back
|
FazBrowse Home
|
New Git URL