I’m using the GnuplotPy interface to use Gnuplot from inside of Python. I’ve found that GnuplotPy complains when I have a newline in a GnuplotPy call. For example:
import Gnuplot
gp = Gnuplot.Gnuplot(persist = 1)
gp('set title "My plot title is very long, \n so it needs two lines"')
...
gp.plot(...)
The above code throws the following error while running:
gnuplot> so it needs two lines
^
line 0: invalid command
And, the above code outputs a plot that only shows the first line of the title, but the plot is otherwise correct. If I remove the \n in the gp('set title...') line, then the error goes away.
According to this Gnuplot tutorial, \n is indeed a valid way of doing a multi-line label in Gnuplot. For example, the tutorial suggests doing this:
set title "This is the title\n\nThis is the x2label"
gnuplot and python both take the 2-character sequence (
\n) as a newline. What’s happening is that python is intercepting your\nand translating it to a literal newline which gnuplot chokes on. Try using a raw string:This will prevent python from intercepting your newline.