Normally when using interactively gnuplot I do:
gnuplot> plot "state_log_6548032.data" using 4 with lines lt -1 lw 0.5 title "X axis" ,\
>"state_log_6548032.data" using 5 with lines lt 1 lw 0.5 title "Y axis" ,\
>"state_log_6548032.data" using 6 with lines lt 2 lw 0.5 title "Z axis"
However when I try to do the same from python using a subprocess:
gnuplot.write( "plot \"%s\" using 1 with lines lt -1 lw 0.5 title 'X axis' ,\ \n" %filename )
gnuplot.write( "plot \"%s\" using 2 with lines lt 1 lw 0.5 title 'Y axis' ,\ \n" %filename )
gnuplot.write( "plot \"%s\" using 3 with lines lt 2 lw 0.5 title 'Z axis' \n" %filename )
I get the following errors:
gnuplot> plot "state_log_6548032.data" using 1 with lines lt -1 lw 0.5 title 'X axis' ,\
^
line 0: invalid character \
gnuplot> plot "state_log_6548032.data" using 2 with lines lt 1 lw 0.5 title 'Y axis' ,\
^
line 0: invalid character \
I have spent a good amount of time trying to figure out if it is a problem with python, but I figured out it's an issue with gnuplot, which uses the escape character for some reason when called from console, but is not required in my case. However my issue remains. How can I plot the data above^^ in succesive lines either from the python subprocess by piping the instructions, or by creating a gnu file from python and calling the gnuplot subprocess to use that file ?
EDIT:
To anyone who might ever get stuck in this simple little thing: as explained below by the nice folk who keep this community alive, Python escapes the "\" when you use "\". So the solution was simply:
gnuplot.write( "plot \"%s\" using 1 with lines lt -1 lw 0.5 title 'X axis' ,\\\n" %filename )
gnuplot.write( "\"%s\" using 2 with lines lt 1 lw 0.5 title 'Y axis' ,\\\n" %filename )
gnuplot.write( "\"%s\" using 3 with lines lt 2 lw 0.5 title 'Z axis' \n" %filename )