Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8185069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T01:43:02+00:00 2026-06-07T01:43:02+00:00

I’m trying to do what the title says. Obviously gnuplot is capable of doing

  • 0

I’m trying to do what the title says. Obviously gnuplot is capable of doing this but I want to use JavaPlot to call it. The Graph3D class in JavaPlot makes me think its possible but as I have found no 3D examples and there’s almost no documentation on JavaPlot, I only have a rough idea how to go about this. If someone already knows how to do this and my efforts are going toward reinventing the wheel, please enlighten me, but for the moment I’ll proceed as if no one has tried to do this before.

Looking at the GNUPlot class, there’s a plot method, but the splot method is commented out and there’s no corresponding method in the GNUPlotExec class. I’ve tried to add one but currently it still plots in 2D. In the interest of full disclosure, I did not make this from scratch, but instead modified the current plot method.

This is the GNUPlot.class splot method that was commented out

    public void splot() throws GNUPlotException {
    exec.splot(param, term);
}

and this is the GNUPlotExec.class splot method derived from the plot method

void splot(GNUPlotParameters par, GNUPlotTerminal terminal) throws GNUPlotException {
    try {
        final GNUPlotTerminal term = terminal;  // Use this thread-aware variable instead of "terminal"
        final String comms = getCommands(par, term); // Get the commands to send to gnuplot
        final Messages msg = new Messages();    // Where to store messages from output threads

        /* Display plot commands to send to gnuplot */
        GNUPlot.getDebugger().msg("** Start of splot commands **", Debug.INFO);
        GNUPlot.getDebugger().msg(comms, Debug.INFO);
        GNUPlot.getDebugger().msg("** End of splot commands **", Debug.INFO);

        /* It's time now to start the actual gnuplot application */
        String[] command;
        if (ispersist) {
            command = persistcommand;
        } else {
            command = nopersist;
        }
        command[0] = getGNUPlotPath();
        {
            String cmdStr = "";
            for (String cmd : command) {
                cmdStr += cmd + " ";
            }
            GNUPlot.getDebugger().msg("exec(" + cmdStr + ")", Debug.INFO);
        }
        final Process proc = Runtime.getRuntime().exec(command);

        /* Windows buffers DEMAND asynchronus read & write */

        /* Thread to process the STDERR of gnuplot */
        Thread err_thread = new Thread() {

            public void run() {
                BufferedReader err = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
                StringBuffer buf = new StringBuffer();
                String line;
                try {
                    while ((line = err.readLine()) != null) {
                        line = parseErrorLine(line, "gnuplot> splot");
                        line = line.replace("input data ('e' ends) >", "").trim();   // Remove entries having the "input data" prompt
                        if (line.equals("^")) {
                            line = "";
                        }  // Ignore line with error pointer
                        if (!line.equals("")) {     // Only take care of not empty lines
                            if (line.indexOf(GNUPlotParameters.ERRORTAG) >= 0) {
                                msg.error = "Error while parsing \'splot\' arguments.";    // Error was found in plot command
                                break;
                            }
                            buf.append(line).append('\n');
                        }
                    }
                    err.close();
                    msg.output = buf.toString(); // Store output stream
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        };
        /* Thread to process the STDOUT of gnuplot */
        err_thread.start();
        Thread out_thread = new Thread() {

            public void run() {
                msg.process = term.processOutput(proc.getInputStream());    // Execute terminal specific output parsing
            }
        };
        out_thread.start();

        /* We utilize the current thread for gnuplot execution */
        OutputStreamWriter out = new OutputStreamWriter(proc.getOutputStream());
        out.write(comms);
        out.flush();
        out.close();


        try {
            proc.waitFor(); // wait for process to finish
            out_thread.join();  // wait for output (terminal related) thread to finish
            err_thread.join();  // wait for error (messages) output to finish
        } catch (InterruptedException ex) {
            throw new GNUPlotException("Interrupted execution of gnuplot");
        }

        /* Find the error message, if any, with precendence to the error thread */
        String message = null;
        if (msg.error != null) {
            message = msg.error;
        } else {
            message = msg.process;
        }

        /* Determine if error stream should be dumbed or not */
        int level = Debug.VERBOSE;
        if (message != null) {
            level = Debug.ERROR;
        }
        GNUPlot.getDebugger().msg("** Start of error stream **", level);
        GNUPlot.getDebugger().msg(msg.output, level);
        GNUPlot.getDebugger().msg("** End of error stream **", level);

        /* Throw an exception if an error occured */
        if (message != null) {
            throw new GNUPlotException(message);
        }

    } catch (IOException ex) {
        throw new GNUPlotException("IOException while executing \"" + getGNUPlotPath() + "\":" + ex.getLocalizedMessage());
    }

}

This is my test I’m trying to run

public static void main(String[] args) {

    GNUPlot p = new GNUPlot("path goes here");

    FunctionPlot myPlot = new FunctionPlot("tan(x)");

    p.addPlot(myPlot);

    p.splot();
}

I believe the commands that are getting executed by gnuplot are

gnuplot> _gnuplot_error = 1
gnuplot> plot tan(x) title 'tan(x)' ; _gnuplot_error = 0
gnuplot> if (_gnuplot_error == 1) print '_ERROR_'
gnuplot>          undefined function: if

and of course that should say splot, not plot

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T01:43:04+00:00Added an answer on June 7, 2026 at 1:43 am

    Figured it out. I needed to add

    p.new3DGraph();
    

    in main before p.addPlot(myPlot);
    Hopefully this will help someone else cause man, there is nothing on JavaPlot out there

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.