mirror of
https://github.com/dkogan/feedgnuplot.git
synced 2025-05-06 06:21:16 +08:00
gnuplot drive now has options for labels
Ignore-this: cd66572ad6410084fe5928187edab99 darcs-hash:20090804173713-0cb85-df03115d7fb93fac9532c3180b740eaec8e1a6ea.gz
This commit is contained in:
parent
d03c5624ce
commit
d61b9bc2ff
@ -10,7 +10,11 @@ my %options = ( "stream" => 1,
|
|||||||
|
|
||||||
GetOptions(\%options,
|
GetOptions(\%options,
|
||||||
"stream!",
|
"stream!",
|
||||||
"lines!");
|
"lines!",
|
||||||
|
"legend:s@",
|
||||||
|
"xlabel:s",
|
||||||
|
"ylabel:s",
|
||||||
|
"title:s");
|
||||||
|
|
||||||
# set up plotting style
|
# set up plotting style
|
||||||
my $style = "points";
|
my $style = "points";
|
||||||
@ -26,8 +30,12 @@ where mandatory options are (in order):
|
|||||||
Stream_YRangeMin Stream_YRangeMax Min and Max y values
|
Stream_YRangeMin Stream_YRangeMax Min and Max y values
|
||||||
|
|
||||||
also
|
also
|
||||||
--[no]stream Do [not] display the data a point at a time, as it comes in
|
--[no]stream Do [not] display the data a point at a time, as it comes in
|
||||||
--[no]lines Do [not] draw lines to connect consecutive points
|
--[no]lines Do [not] draw lines to connect consecutive points
|
||||||
|
--xlabel xxx Set x-axis label
|
||||||
|
--ylabel xxx Set y-axis label
|
||||||
|
--title xxx Set the title of the plot
|
||||||
|
--legend xxx Set the label for a curve plot. Give this option multiple times for multiple curves
|
||||||
OEF
|
OEF
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
@ -68,6 +76,16 @@ sub main {
|
|||||||
print PIPE "set style data $style\n";
|
print PIPE "set style data $style\n";
|
||||||
print PIPE "set grid\n";
|
print PIPE "set grid\n";
|
||||||
|
|
||||||
|
print(PIPE "set xlabel \"" . $options{"xlabel"} . "\"\n") if $options{"xlabel"};
|
||||||
|
print(PIPE "set ylabel \"" . $options{"ylabel"} . "\"\n") if $options{"ylabel"};
|
||||||
|
print(PIPE "set title \"" . $options{"title" } . "\"\n") if $options{"title"};
|
||||||
|
|
||||||
|
my @legend;
|
||||||
|
# for the specified values, set the legend entries to 'legend "title 1"', etc
|
||||||
|
@legend = map({"title \"$_\""} @{$options{"legend"}}) if($options{"legend"});
|
||||||
|
# now append "notitle" to all the non-specified legend entries
|
||||||
|
push @legend, ("notitle") x ($numberOfStreams - @legend);
|
||||||
|
|
||||||
for(my $i=0; $i<$numberOfStreams; $i++) {
|
for(my $i=0; $i<$numberOfStreams; $i++) {
|
||||||
push @buffers, [];
|
push @buffers, [];
|
||||||
}
|
}
|
||||||
@ -89,7 +107,7 @@ sub main {
|
|||||||
$streamIdx++;
|
$streamIdx++;
|
||||||
if ($streamIdx == $numberOfStreams) {
|
if ($streamIdx == $numberOfStreams) {
|
||||||
$streamIdx = 0;
|
$streamIdx = 0;
|
||||||
plotStoredData($xlast, $samples, $numberOfStreams, *PIPE, \@buffers) if($options{"stream"});
|
plotStoredData($xlast, $samples, $numberOfStreams, *PIPE, \@buffers, \@legend) if($options{"stream"});
|
||||||
$xlast++;
|
$xlast++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,18 +121,18 @@ sub main {
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$samples = @{$buffers[0]};
|
$samples = @{$buffers[0]};
|
||||||
plotStoredData($xlast, $samples, $numberOfStreams, *PIPE, \@buffers);
|
plotStoredData($xlast, $samples, $numberOfStreams, *PIPE, \@buffers, \@legend);
|
||||||
}
|
}
|
||||||
sleep 100000;
|
sleep 100000;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub plotStoredData
|
sub plotStoredData
|
||||||
{
|
{
|
||||||
my ($xlast, $samples, $numberOfStreams, $pipe, $buffers) = @_;
|
my ($xlast, $samples, $numberOfStreams, $pipe, $buffers, $legend) = @_;
|
||||||
|
|
||||||
my $x0 = $xlast - $samples + 1;
|
my $x0 = $xlast - $samples + 1;
|
||||||
print $pipe "set xrange [$x0:$xlast]\n";
|
print $pipe "set xrange [$x0:$xlast]\n";
|
||||||
print $pipe 'plot ' . join(', ' , ('"-" notitle') x $numberOfStreams) . "\n";
|
print $pipe 'plot ' . join(', ' , map({ "\"-\" $_"} @$legend) ) . "\n";
|
||||||
|
|
||||||
foreach my $buf (@{$buffers})
|
foreach my $buf (@{$buffers})
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user