Thread Skript zum plotten von Diagrammen / Kurven
(12 answers)
Opened by Koerschgen at 2016-03-21 20:50
Hier eine Lösung in Perl + Gnuplot: ist im Prinzip das Beispiel aus Chart::Gnuplot übernommen.
Code (perl): (dl
)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 use Chart::Gnuplot; use strict; use warnings; sub createDs { my ($dsX, $dsY, $name) = @_; my $dataSet = Chart::Gnuplot::DataSet->new( xdata => [@$dsX], ydata => [@$dsY], title => $name, style => "linespoints"); return $dataSet; } sub readDatasets { my $filename = shift; my $name = "unnamed"; my @result; my (@dataX, @dataY); open my $fh, '<', $filename; while (my $line = <$fh>) { if ($line =~ /^\*\*/) { if (@dataX) { push @result, createDs(\@dataX, \@dataY, $name); @dataX = (); @dataY = (); } next; } if ($line =~ /^\*/) { if ($line =~ /NAME=(.+)/) { $name = $1; } next; } if ($line =~ /(.+), (.+?)$/) { push @dataX, $1; push @dataY, $2; } } if (@dataX) { push @result, createDs(\@dataX, \@dataY, $name); } return @result; } # Create chart object and specify the properties of the chart my $chart = Chart::Gnuplot->new( output => "/tmp/koer.png", title => "Simple testing", xlabel => "My x-axis label", ylabel => "My y-axis label", ); my @ds = readDatasets("koer.dat"); # Plot the data set on the chart $chart->plot2d(@ds); Last edited: 2016-03-22 00:25:00 +0100 (CET) |