NAME
Lab::Moose::DataFile::Gnuplot - Text based data file ('Gnuplot style')
VERSION
version 3.910
SYNOPSIS
use Lab::Moose;
my $folder = datafolder();
# datafile with two simple 2D plots:
my $file = datafile(
type => 'Gnuplot',
folder => $folder,
filename => 'gnuplot-file.dat',
columns => [qw/time voltage temp/]
);
# add live plot
$file->add_plot(
x => 'time',
y => 'voltage',
curve_options => {with => 'points'},
);
$file->add_plot(
x => 'time',
y => 'temp',
hard_copy => 'gnuplot-file-time-temp.png'
);
# or both curves in one plot
$file->add_plot(
curves => [
{x => 'time', y => 'voltage'},
{x => 'time', y => 'temp', curve_options => {axes => 'x1y2'}}
]
);
$file->log(time => 1, voltage => 2, temp => 3);
# datafile with pm3d plot
my $datafile = datafile(
type => 'Gnuplot',
folder => datafolder(),
filename => 'data.dat',
columns => [qw/x y z/],
comment_string => "COLUMNS#\t"
);
$datafile->add_plot(
type => 'pm3d',
x => 'x',
y => 'y',
z => 'z',
hard_copy => 'data.png',
);
for my $x (0..100) {
for my $y (0..100) {
$datafile->log(x => $x, y => $y, z => rand());
}
$datafile->new_block();
}
METHODS
new
Supports the following attributtes in addition to the Lab::Moose::DataFile requirements:
columns
(mandatory) arrayref of column names
precision
The numbers are formatted with a
%.${precision}g
format specifier. Default is 10.
log
$file->log(column1 => $value1, column2 => $value2, ...);
Log one line of data.
log_block
$file->log_block(
prefix => {column1 => $value1, ...},
block => $block,
add_newline => 1
);
Log a 1D or 2D PDL or array ref. The first dimension runs over the datafile rows. You can add prefix columns, which will be the same for each line in the block. E.g. when using a spectrum analyzer inside a voltage sweep, one would log the returned PDL prefixed with the sweep voltage.
new_block
$file->new_block()
print "\n" to the datafile.
log_comment
$file->log_comment(comment => $string);
log a comment string, which will be prefixed with '#'. If $string
contains newline characters, several lines of comments will be written.
add_plot
$file->add_plot(
type => 'pm3d',
x => 'x-column',
y => 'y-column',
z => 'z-column',
plot_options => {grid => 1},
hard_copy => 'myplot.png',
hard_copy_terminal => 'svg',
);
Add a new live plot to the datafile. Options:
type
Supported types:
points (default), pm3d
.x (mandatory)
Name of the column which is used for the x-axis.
y (mandatory)
Name of the column which is used for the y-axis.
z (mandatory for 'pm3d' plot type)
Name of the column which is used tor the cb-axis in a pm3d plot.
legend (only for '2d' plot type)
For datafiles with multiple blocks, name of the column which is used to label the curves (See example in Lab::Measurement::Tutorial).
terminal
gnuplot terminal. If not set, use default gnuplot terminal.
terminal_options
HashRef of terminal options. This defaults to
{persist => 1, raise => 0, enhanced => 0}
. The different graphical terminal types (qt,x11,wxt) show different behaviour regarding persistent windows. For wxt, the plot windows are closed when the datafile object goes out of scope. To prevent this, push each new datafile object onto a global array.plot_options
HashRef of plotting options (See PDL::Graphics::Gnuplot for the complete list). Those are appended to the default plot options.
curve_options
HashRef of curve options (See PDL::Graphics::Gnuplot for the complete list).
refresh
Set this to a string, if you need to refresh the plot manually with the
refresh_plots
option. Multiple plots can share the same refresh handle string.Predefined refresh types:
'point'
Default for 2D plots. Replot for each new row.
'block'
Default for 3D plots. Replot when finishing a block.
refresh_interval
Minimum time between replots. Default: replot as often as
refresh
attribute allows.hard_copy
Filename for the copy of the plot in the data folder. Default: Switch datafile filename suffix of datafile to the $terminal, e.g. data.dat => data.png. Mandatory if you add multiple plots to one datafile.
hard_copy_suffix
Filename suffix for the copy of the plot in the data folder. The filename off the copy will be basename off the datafile with this suffix added.
hard_copy_terminal
Terminal for hard_copy option. Use png terminal by default. The 'output' terminal option must be supported.
live
Set to false to only create the hardcopy and no live plot.
$file->add_plot( live => 0, ..., );
refresh_plots
$file->refresh_plots(refresh => $refresh_type);
# or
$file->refresh_plots();
Call refresh_plot
for each plot with hanle $handle
.
If the handle
argument is not given, refresh all plots.
COPYRIGHT AND LICENSE
This software is copyright (c) 2024 by the Lab::Measurement team; in detail:
Copyright 2016 Simon Reinhardt
2017 Andreas K. Huettel, Simon Reinhardt
2018-2019 Simon Reinhardt
2021 Simon Reinhardt
2022 Mia Schambeck
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.