Created
June 8, 2012 16:56
-
-
Save naruhito/2896859 to your computer and use it in GitHub Desktop.
Perl/Chart::Gnuplot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/path/to/perl | |
use strict; | |
use warnings; | |
use Chart::Gnuplot; | |
my @data_sets; | |
my @x_data = (0, 1, 2, 3, 4); | |
my @y_data = (4, 3, 2, 1, 0); | |
$data_sets[0] = Chart::Gnuplot::DataSet->new( | |
xdata => \@x_data, | |
ydata => \@y_data, | |
style => 'linespoints pointtype 3 pointsize 2.0 linetype rgb "black" linewidth 5.0', | |
title => '{/Symbol l} = 123', | |
); | |
my ($val_a, $val_b, $val_c) = (1, -10, 25); | |
$data_sets[1] = Chart::Gnuplot::DataSet->new( | |
func => "$val_a*(x**2) + $val_b*x + $val_c", | |
style => 'lines linetype 1 linewidth 1.0', | |
title => 'x^2 - 10x + 25', | |
); | |
my $write_fh = IO::File->new( 'dummy.data', 'w' ); | |
$write_fh->print( "$_\t$_\n" ) for 0..10; | |
$data_sets[2] = Chart::Gnuplot::DataSet->new( | |
datafile => 'dummy.data', | |
style => 'points pointtype 7 pointsize 1.0', | |
title => 'y_0', | |
); | |
my $chart = Chart::Gnuplot->new( | |
terminal => 'postscript color enhanced', | |
output => 'sample.eps', | |
title => { | |
text => 'Sample Graph G_0', | |
enhanced => 'on', | |
}, | |
size => 0.7, # 'square', | |
xlabel => { | |
text => 'X_{sample}', | |
enhanced => 'on', | |
}, | |
ylabel => { | |
text => 'Y_{sample}', | |
enhanced => 'on', | |
}, | |
xtics => 1, | |
ytics => 2, | |
xrange => [0, 10], | |
yrange => [0, 10], | |
key => 'right bottom', | |
); | |
$chart->plot2d(@data_sets); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment