0

I have written a python script where I have taken mu = input('Enter some number'). Now I have used subprocess module to write a gnuplot script inside the python script. My gnuplot code is:

set zeroaxis
set xrange[-5:5]
set yrange[-5:5]
f(x,y) = (mu*y+x-x**2+x*y)/y
g(x,y) = sqrt(1+f(x,y)**2)
plot "++" using ($1-.1/g($1,$2)):($2-.1*f($1,$2)/g($1,$2)):(.2/g($1,$2)):(.2*f($1,$2)/g($1,$2)) with vectors lw 1,'data.dat' u 1:2 w l
pause -1`

But in this case to run the program I have to define mu inside this gnuplot script. I don't want to do like this. I want to pass mu from python input to gnuplot, I don't want to define mu again inside gnuplot. Because after doing that I have to change the value of mu every time as I take input of mu in python. Do anybody have a solution to this, how to pass variable inside gnuplot or how to take input in gnuplot like python? Thank you.

sm10
  • 9
  • 1
  • 5
  • 1
    http://stackoverflow.com/a/12330483/469220 – Vlad Sep 05 '15 at 10:43
  • 3
    Use gnuplot's `-e` parameter, see e.g. http://stackoverflow.com/q/12328603/2604213 – Christoph Sep 05 '15 at 10:43
  • 1
    just in case: http://matplotlib.org/ is a very powerful plotting library for python. – hiro protagonist Sep 05 '15 at 10:45
  • so, my code should be `gnuplot -e "mu=1" foo.plt`. but i don't want to enter `mu` again. is there any possibility so that i don't have to reenter `mu` in gnuplot script, once i have taken it as input in python and use that same `mu` into gnuplot script? – sm10 Sep 05 '15 at 11:33
  • Yes, you can. But that is part of the python code which you don't show, like `cmd = "gnuplot -e 'mu={0}' foo.plt". format(mu)`. – Christoph Sep 05 '15 at 12:50

0 Answers0