如何将数据重新排列为 GD::Graph 的 (x,y) 坐标?
我正在编写一个程序,它接受用户的输入文件。 该文件中有一堆数字,我将读取文件中的数字并使用 GD::图表。
文件的第一行是 X 轴,文件的第二行是 X 轴对应的 Y 值以及第三、第四……等 例如:
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)
我计划阅读每一行数组,然后按空格或制表符分割行并将值存储在数组中。 因此,数组 1 将具有 x 轴,数组 2 将具有 y 轴,但是我应该如何在数组中存储第 3、4、5、...等行,以便它们变为 (x,y)?
此外,如何找到第一行和第二行(2 个数组)的最大值,以便为 X 轴和 Y 轴创建限制?
I am writing a program that takes in an input file from the user. The file has bunch of numbers in it and I will read the numbers in the file and create a plot based on those numbers using GD::Graph.
The first line of the file is X axis, second line of the file is Y values corresponding to X axis and third, fourth, ..., etc For example:
1 2 3 4 5
2 4 5 10 14
5 6 8 12 13
So in the above, first line is x-axis, second is y values corresponding to xaxis so this will fetch 10 points. (1, 2) (1, 5) (2, 4) (2, 6)....(4,10) (4,12) (5,14) (5, 13)
I plan on reading each line of the array and then splitting the line on spaces or tabs and storing the values in an array. So, array 1 will have x-axis, array2 will have y-axis, but how should I store 3rd, 4th, 5th, ..., etc lines in an array so they become (x,y)?
Furthermore, how can I find the largest value for the first and second lines (2 arrays) so I can create a limit for my X and Y axes?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
并不是您问题的真正答案,但不要错过 GD::Graph: :数据。
除非您确定每行的第一行和最后一行是最小/最大的,否则您需要使用类似 List::Util 的
min()
和max()
。我不太明白你所说的“文件的第一行是X轴,文件的第二行是Y轴,第三行、第四行……等是X轴的对应点”是什么意思。
Not really an answer to your question, but don't miss GD::Graph::Data.
Unless you are sure that the first and last on each line is smallest/biggest you'll need to use something like List::Util's
min()
andmax()
.I don't really understand what you mean by "The first line of the file is X axis, second line of the file is Y axis and third, fourth, ..., etc are corresponding points to X axis."
您可以随时增加 x 和 y 数组。
You can grow your x and y arrays as you go.
哎呀,误读了问题,您想要 AoAoH 或 AoH,具体取决于第一条线之后的每条线是否代表一条线,或者都只是分别绘制的点。 如果文件中的每一行都成为图中的一条线,我会这样写:
如果它们只是要绘制的点,我会这样处理它:
Whoops, misread the question, you want either an AoAoH or an AoH, depending on whether each line after the first represents a line or the are all just points to be plotted respectively. Here is how I would write it if each line in the file was to become a line in the graph:
And here is how I would handle it if they are just points to be ploted: