Skip to content

Instantly share code, notes, and snippets.

@mmisono
Created May 12, 2010 09:41
Show Gist options
  • Save mmisono/398391 to your computer and use it in GitHub Desktop.
Save mmisono/398391 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use warnings;
use GD::Graph::linespoints;
use GD::Graph::colour qw(:colours);
use GD::Text;
#データファイルのオープン
open DATA ,"<data.txt" or die("Can't Open data file");
my (@xaxis,@yaxis);
#データの読み込み
for (<DATA>){
my @line = split(/\s+/);
push(@xaxis,$line[0]);
push(@yaxis,$line[1]);
}
close DATA;
#グラフを作成
my @data = (\@xaxis,\@yaxis);
my $graph = GD::Graph::linespoints->new(400,300);
$graph->set(
bgclr => "lgray", #背景色
boxclr => "lgray", #グラフの背景色
fgclr => "blue", #軸とグリッドの色
labelclr => "black", #ラベルの文字色
valuesclr => "black", #値を示す文字色
axislabelclr => "black", #軸のラベルの文字色
textclr => "black", #上記以外の文字色
dclrs => [ "red" ], #グラフの色
title => "フィボナッチ数の計算時間(再帰版)", #タイトル
x_label => "fib(n)", #X軸のラベル
y_label => "時間(s)", #Y軸のラベル
x_label_position => 1/2, #X軸のラベルの位置(デフォルトは3/4)
y_max_value => 200, #Y軸の最大値
long_ticks => 1, #目盛線を表示
markers => [7] #プロットの種類(丸)
);
#フォントの指定
GD::Text->font_path("/System/Library/Fonts/");
$graph->set_title_font( "AquaKana.ttc", 12 ); #タイトル
$graph->set_x_axis_font( "AquaKana.ttc", 8 ); #X軸目盛
$graph->set_x_label_font( "AquaKana.ttc", 11); #X軸ラベル
$graph->set_y_axis_font( "AquaKana.ttc", 8 ); #Y軸目盛
$graph->set_y_label_font( "AquaKana.ttc", 11); #Y軸ラベル
#画像の出力
my $img = $graph->plot(\@data)->png or die ("Cannnot create image");
open OUT, ">recfib.png" or die("Can't Open PNG file");
binmode OUT;
print OUT $img;
close OUT;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment