The problem is the clear command in your script. It acts like a hypothetical command plot blank page. Then the script issues a reset and another plot command. The result is a file containing two separate svg documents, the first one blank and the second one from the plot command. But svg files are only allowed to contain a single document, hence the error you see.
Solution (1) Do not issue a clear command.
Solution (2) If you must issue a clear for some reason (why would this be?), wrap the whole series of commands in set multiplot; ... unset multiplot;
The clear command exists so that you can erase the current plot window in an interactive session or erase a portion of the total canvas being created inside set multiplot. For svg that first use makes no sense, so it should only be used inside a multiplot.
Possibly gnuplot should issue an error message when it sees a clear command in a context that makes no sense, but that may be difficult to determine in the general case.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The problem is the
clearcommand in your script. It acts like a hypothetical commandplot blank page. Then the script issues aresetand another plot command. The result is a file containing two separate svg documents, the first one blank and the second one from theplotcommand. But svg files are only allowed to contain a single document, hence the error you see.Solution (1) Do not issue a
clearcommand.Solution (2) If you must issue a
clearfor some reason (why would this be?), wrap the whole series of commands inset multiplot; ... unset multiplot;The
clearcommand exists so that you can erase the current plot window in an interactive session or erase a portion of the total canvas being created insideset multiplot. For svg that first use makes no sense, so it should only be used inside a multiplot.Possibly gnuplot should issue an error message when it sees a
clearcommand in a context that makes no sense, but that may be difficult to determine in the general case.