2

I have simple python script (smazat.py) that generate some data

for i in range(50):
    print i, i-20

I can make images in windows command line with following command

smazat.py | gnuplot -e "set term png;p '-'" > smazat.png

however when use gnuplot script with the same commands like this

smazat.py | gnuplot smazat.gp > smazat.png

it does not work. What's happening?

skytaker
  • 4,159
  • 1
  • 21
  • 31
OlejzMaku
  • 35
  • 1
  • 4
  • 1
    Use `plot '< cat -'`, see [pipe plot data to gnuplot script](http://stackoverflow.com/a/17576571/2604213). – Christoph Oct 06 '14 at 11:43
  • possible duplicate of [pipe plot data to gnuplot script](http://stackoverflow.com/questions/17543386/pipe-plot-data-to-gnuplot-script) – Christoph Oct 06 '14 at 11:44
  • `plot '< cat -'` does not work in windows – OlejzMaku Oct 09 '14 at 11:08
  • Ups, I overlooked that you are on Windows. See my answer for a little python script which passes stdin to stdout and can be used like cat in this situation. – Christoph Oct 09 '14 at 11:39

1 Answers1

2

If you are on a Unix system, you can use

plot `< cat -`

to achieve this (see pipe plot data to gnuplot script).

On Windows, and since you're using python anyway, you can write a small cat.py python script which passes stdin to stdout:

Script cat.py

from __future__ import print_function
import sys
for line in sys.stdin:
    print(line, file=sys.stdout, end='')

Plot file plot.gp

set term png
plot '< python cat.py'

And then call this with

python smazat.py | gnuplot plot.gp > smazat.png
Community
  • 1
  • 1
Christoph
  • 47,569
  • 8
  • 87
  • 187