GnuplotEx.Port (gnuplot_ex v0.5.0)

Port-based communication with gnuplot.

Handles spawning gnuplot processes, sending commands and data, and collecting results.

Large Dataset Support

For large datasets, the port automatically scales timeout based on data size. You can also provide a progress callback to monitor transmission:

GnuplotEx.render(plot, :svg,
  on_progress: fn sent, total -> IO.puts("Progress: #{sent}/#{total}") end
)

Summary

Functions

Execute gnuplot commands with optional datasets.

Execute commands and return captured stdout.

Find the gnuplot executable path.

Functions

execute(command_string, datasets, opts \\ [])

@spec execute(String.t(), [Enumerable.t()], keyword()) ::
  {:ok, String.t()} | {:error, term()}

Execute gnuplot commands with optional datasets.

Opens a gnuplot port, sends the command string, streams datasets, and returns the result.

Parameters

  • command_string - The gnuplot script to execute
  • datasets - List of datasets (each formatted via Dataset protocol)
  • opts - Options:
    • :on_progress - Callback fn(sent, total) -> any for progress monitoring
    • :timeout - Override base timeout (ms), default 10_000

Returns

  • {:ok, command_string} - Success
  • {:error, :gnuplot_not_found} - gnuplot not in PATH
  • {:error, {:exit, code, output}} - gnuplot exited with error
  • {:error, :timeout} - Execution timed out

Example

iex> cmd = "set terminal dumb; plot sin(x)"
iex> GnuplotEx.Port.execute(cmd, [])
{:ok, "set terminal dumb; plot sin(x)"}

# With progress callback
GnuplotEx.Port.execute(cmd, [data],
  on_progress: fn sent, total -> IO.puts("Progress: #{sent}/#{total}") end
)

execute_capture(command_string, datasets, opts \\ [])

@spec execute_capture(String.t(), [Enumerable.t()], keyword()) ::
  {:ok, String.t()} | {:error, term()}

Execute commands and return captured stdout.

Used for dumb terminal output (ASCII art).

find_executable()

@spec find_executable() :: {:ok, charlist()} | {:error, :gnuplot_not_found}

Find the gnuplot executable path.

Returns {:ok, path} if found, {:error, :gnuplot_not_found} otherwise.

Example

iex> GnuplotEx.Port.find_executable()
{:ok, ~c"/usr/bin/gnuplot"}