質問

I have a Java program which starts GNUPlot.

Runtime.getRuntime().exec("gnuplot");

Java communicates with it over the output stream. Now I'm creating lots of different terminals with different plots.

set term wxt [terminalId]

The plot command for the different terminals consists of function plotting and plotting of data points (so the plot command is like "plot sin(x), cos(x), '-';" ). The data points are sent in this format:

0 0;
1 1;
2 2;
3 3;
e;

I'm trying to export the finished plots to PNG (or a different image format).

for(int terminalId = 0; terminalId < lastTerminalId; terminalId++) {
        gnuPlotter.sendCommand("set term pngcairo size " + width + "," + height + ";");
        gnuPlotter.sendCommand("set output 'terminal" + terminalId + ".png';");
        gnuPlotter.sendCommand("replot;");
    }

My problem is that my data points aren't replotted. I think replot is really only sending the "plot ..." command again, but isn't repeating the listing of data point which should be send afterwards. How can I plot exactly what's already on the WXT terminals on the PNG terminal again?

役に立ちましたか?

解決

For anyone not using Java, the problem can be reproduced from the shell like this:

gnuplot <<EOF
p sin(x), cos(x), '-'
0 0
1 1
2 2
e
set term png
set out 'plt.png'
rep
EOF

You can get round it by plotting the data from stdin to an intermediate table:

gnuplot <<EOF
set table 'term1.dat'
plot '-' 
0 0
1 1
2 2
e
unset table
plot sin(x), cos(x), 'term1.dat'
set term png
set out 'plt.png'
rep
EOF
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top