All of the information I'm finding about using JavaPlot is about how to create plots and run them from a Java code-level. This is fine, but I already have some script files used that do what I want them to outside of Jave when a user executes them. Right now, I can open Gnuplot, and type the commands
gnuplot> load "script.plt"
And it will output me a nice .png graphic of the plot I have. In the script, one of the lines called is
plot "graphData.dat" title "Line Title"
The file 'graphData.dat' stores the co-ordinate information needed to plot my graph.
This works fine when the user double-clicks the 'script.plt' file in its folder (I'm running in a Windows environment). This is pretty flawless (minus the fact that the gnuplot process doesn't end properly, which is not what I'm asking about but if it rings any bells, I'd love to hear how to fix that, too).
The problem I'm facing is that I need to be able to run the script through gnuplot through a java environment. My program needs to automatically export a .png graphic using gnuplot. I've done some looking around, and JavaPlot seems to be the library of choice for Java Support in Gnuplot, but I can't get it to do what I want: simply running an instance of gnuplot that calls the aforementioned load command.
Any help or advice I can get would be appreciated, I've tried forsaking the script file, I've tried to dynamically call the load command (but not from the correct place, apparently), and I've tried plotting the .dat file directly, which it really doesn't like. As long as I can get that script running, I'm set.
One thing that I notice right away: simply loading a script from the gnuplot prompt (i.e.)
is completely equivalent to passing the script name as the first argument to gnuplot on the commandline (i.e.)
This is also equivalent to
gnuplot -e 'load "script.plt"'
from the commandline. This simplifies your problem because now you don't need to figure out how to communicate with gnuplot via pipes, you only need to figure out how to issue a system call inJava
-- A task which I would assume is reasonably simple for someone who codes injava
. Inpython
, I could doimport os; os.system("gnuplot script.plt")
.I think the second, third and fourth answers in the link posted by @andersoj gives an examples and links.