どのように組み替えデータとして使用することができるx,y)座標GD::Graph?

StackOverflow https://stackoverflow.com/questions/714494

  •  23-08-2019
  •  | 
  •  

質問

皆様にお伝えしたくて書き込みプログラムからの入力ファイルからのユーザーです。のファイルのバンチの番号で読み込みまでの数字のファイルをプロットを作成するに基づく数値を使用 GD::Graph.

最初の行はファイルのファイルがX軸、第二のファイルのY値に対応するX軸および第三に、第四に、...など、例えば:

1 2 3 4 5 
2 4 5 10 14
5 6 8 12 13

このように、最初の行はx軸、y値に対応するxaxisでこれを取得す10。(1, 2) (1, 5) (2, 4) (2, 6)....(4,10) (4,12) (5,14) (5, 13)

Iプランお読みの各ラインの配列を分割する線スペースまたはタブを保存する値を配列に格納します。なので、配列1においてx軸、array2ますy軸が、いつ、どのように店舗3、4、5、...などライン配列と(x,y)?

また、どうすることができますので、最大の価値第一、第二線(2つの配列が互いを制限は私のXおよびY軸?

役に立ちましたか?

解決

消へのリモーに質問したいのどちらかAoAoHやAoHかどうかに応じて、各行の最初を表す線のすべてだけでポイントに示されます。ここではどのように書く場合は各ラインのファイルなラインをグラフ:

#!/usr/bin/perl

use strict;
use warnings;
use List::Util qw/min max/;

my @x_points         = split " ", scalar <>; #read in the x axis labels
my ($x_min, $x_max)  = (sort { $a <=> $b } @x_points)[0,-1];
my ($y_min, $y_max)  = (0, 0);

#lines is an AoAoH, first layer are the lines to be drawn
#second layer is a list of coords
#third layer are the x and y coords
my @lines;
while (<>) {
    my @y_points = split;
    #if the two arrays are not the same size, we have a problem
    die "invalid file\n" unless @y_points == @x_points;

    $y_min = max($y_min, @y_points);
    $y_max = min($y_max, @y_points);

    push @lines, [ 
        map { { x => $x_points[$_], y => $y_points[$_] } }  
    0 .. $#x_points 
    ];
}

use Data::Dumper;

print "x min and max $x_min $x_max\n",
      "y min and max $y_min $y_max\n",
      "data:\n",
      Dumper(\@lines);

my $i;
for my $line (@lines) {
    $i++;
    print "line $i is made up of points: ",
        (map { "($_->{x}, $_->{y}) " } @$line), "\n";
}

これからも、どう対応すればいでいるだけポイントploted:

#!/usr/bin/perl

use strict;
use warnings;
use List::Util qw/min max/;

my @x_points         = split " ", scalar <>; #read in the x axis labels
my ($x_min, $x_max)  = (sort { $a <=> $b } @x_points)[0,-1];
my ($y_min, $y_max)  = (0, 0);

#lines is an AoAoH, first layer are the lines to be drawn
#second layer is a list of coords
#third layer are the x and y coords
my @points;
while (<>) {
    my @y_points = split;
    #if the two arrays are not the same size, we have a problem
    die "invalid file\n" unless @y_points == @x_points;

    $y_min = max($y_min, @y_points);
    $y_max = min($y_max, @y_points);

    push @points,
        map { { x => $x_points[$_], y => $y_points[$_] } }
        0 .. $#x_points;
}

use Data::Dumper;

print "x min and max $x_min $x_max\n",
      "y min and max $y_min $y_max\n",
      "data:\n",
      Dumper(\@points);

print "Here are the points: ", 
    (map { "($_->{x}, $_->{y}) " } @points), "\n";

他のヒント

だ不明な点があれば、ここでお答えでお見逃しなく GD::Graph::データ.

を除き、 確認 その最初と最後の各ラインは最小/最大できます。ようなもの リスト::Util's min()max().


思いもあり、最初の行はファイルのファイルがX軸、第二のファイルはY軸及び第三に、第四に、...などに対応する点のX軸となる。"

成長できたxとyの配列としてとても苦手なのでお願いします。

#!/usr/bin/perl

use Data::Dumper;
use warnings;
use strict;

my @xs = ();
my @ys = ();
my $expecting_xs = 1;
my $last_xs_count;

while(<>) {
  chomp;
  my @values = split(/\s+/);
  if($expecting_xs) {
    push(@xs, @values);
    $last_xs_count = @values;
    $expecting_xs = 0;
  } else {
    if(@values != $last_xs_count) {
      die "Count mismatch";
    } 
    push(@ys, @values);
    $expecting_xs = 1;
  }
}

if(!$expecting_xs) {
  die("Odd number of lines");
}

my($xmin, $xmax) = extremes(@xs);
my($ymin, $ymax) = extremes(@ys);

print "xmin: $xmin xmax: $xmax ymin: $ymin ymax: $ymax\n";
print Dumper(\@xs), Dumper(\@ys);

sub extremes {
  my(@values) = @_;
  return undef unless @values;
  my $min = shift(@values);
  my $max = $min;
  for my $value (@values) {
    $max = $value if $value > $max;
    $min = $value if $value < $min;
  }
  return $min, $max;
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top