GnuplotEx.Dataset.Binary (gnuplot_ex v0.5.1)
Binary data formatting for gnuplot.
Provides functions to write data in gnuplot's binary format for faster transmission of large datasets. Uses temporary files which are cleaned up after rendering.
Gnuplot Binary Format
Gnuplot expects binary data as raw IEEE 754 doubles (64-bit floats) with native byte order:
plot 'data.bin' binary format='%double%double' using 1:2Example
# Write binary data
{:ok, path, format} = Binary.write_temp([[1.0, 2.0], [3.0, 4.0]])
# path = "/tmp/gnuplot_xxx.bin"
# format = "%double%double"
# Clean up after use
Binary.cleanup([path])
Summary
Functions
Clean up temporary binary files.
Count the number of columns in the first row of data.
Generate gnuplot format string based on column count.
Write data to a temporary file in binary format.
Functions
@spec cleanup([String.t()]) :: :ok
Clean up temporary binary files.
Silently ignores files that don't exist or can't be deleted.
Example
Binary.cleanup(["/tmp/gnuplot_xxx.bin", "/tmp/gnuplot_yyy.bin"])
@spec column_count(Enumerable.t()) :: non_neg_integer()
Count the number of columns in the first row of data.
Returns 0 for empty data.
Examples
iex> GnuplotEx.Dataset.Binary.column_count([[1, 2, 3], [4, 5, 6]])
3
iex> GnuplotEx.Dataset.Binary.column_count([])
0
@spec format_string(non_neg_integer()) :: String.t()
Generate gnuplot format string based on column count.
Examples
iex> GnuplotEx.Dataset.Binary.format_string(2)
"%double%double"
iex> GnuplotEx.Dataset.Binary.format_string(3)
"%double%double%double"
@spec write_temp( Enumerable.t(), keyword() ) :: {:ok, String.t(), String.t()} | {:error, term()}
Write data to a temporary file in binary format.
Returns {:ok, path, format_string} where:
pathis the temp file pathformat_stringis the gnuplot format specifier (e.g.,"%double%double")
Options
:prefix- Temp file prefix (default:"gnuplot_")
Example
{:ok, path, format} = Binary.write_temp([[1.0, 2.0], [3.0, 4.0]])