简体   繁体   English

从GNUPlott中的CSV文件仅打印某​​些行

[英]Printing Only certain Rows from a CSV File in GNUPlott

I have a very specific question using csv files and GNUPlots. 我在使用csv文件和GNUPlots时有一个非常具体的问题。

What I am trying to do programmatically in Python, is print a set of graphs with gnuplots. 我想用Python编程地做的是用gnuplots打印一组图形。

The specific problem I am trying to resolve is that I have csv files are a set of parsed data, processed from servers, with multiple columns. 我要解决的特定问题是csv文件是一组解析的数据,是从服务器处理的,具有多列。

In the first column there is a server names, some other columns which I do not need to care about right now, then my time columns and data columns. 在第一列中有一个服务器名称,另外一些我现在不需要关心的列,然后是我的时间列和数据列。

What I am trying to is for each specific Server (let's call them A, B, and C) take the corresponding data for time and value - and plot these onto a gnuplot where each line is a separate server. 我要为每个特定的服务器(我们分别称为A,B和C)获取时间和值的相应数据-并将它们绘制到gnuplot上,其中每行都是单独的服务器。 So let's say the data looks something like this 所以说数据看起来像这样

Server Time Data 服务器时间数据
A****** T1*** D1 A ****** T1 *** D1
A****** T2*** D2 A ****** T2 *** D2
A****** T3*** D3 A ****** T3 *** D3
B****** T1*** D1 B ****** T1 *** D1
B****** T2*** D2 B ****** T2 *** D2
B****** T3*** D3 B ****** T3 *** D3
C****** T1*** D1 C ****** T1 *** D1
C****** T2*** D2 C ****** T2 *** D2
C****** T3*** D3 C ****** T3 *** D3

--This is simplified but accurate enough to pose solutions-- --Now this ABC formula - the pattern can vary, and number of times and such can vary so I cannot assume anything like every third server is the next server or something formulaic like this - so I need some kind of comparison or "checking" mechanism. -这是简化的方法,但足够精确,可以提出解决方案--现在,此ABC公式-模式可以变化,并且次数可以变化,所以我不能假设每隔三台服务器就是下一个服务器或类似的公式这-所以我需要某种比较或“检查”机制。

So what I need to do in gnuplott, is to match the first column and grab the x,y data from that row, for each instance of the server in that file, and rinse and repeat for each server in the file -- So I have a gnuplott of time vs data with all servers in the file. 因此,我需要在gnuplott中进行匹配,以匹配该文件中服务器的每个实例的第一列并从该行中获取x,y数据,然后对该文件中的每个服务器进行冲洗和重复-所以我文件中所有服务器的时间与数据的时间成正比。

After spending awhile on it - and reading the documentation I had considered using the ternary operator but - the issue I am having is that I am matching text fields - and then getting corresponding data by row in a csv. 在花了一段时间后-阅读了我曾考虑使用三元运算符的文档,但是-我遇到的问题是我正在匹配文本字段-然后在CSV中逐行获取相应的数据。

The resolutions I have come to are just to parse the csv files by server into tempfiles - then simply plot the data from each temp file into the graph by using the simple plot column x column methodology in gnuplot ([x:y]) for each tempfile. 我要解决的只是将服务器的csv文件解析为tempfile,然后使用gnuplot([x:y])中的简单图列x列方法,将每个临时文件中的数据绘制到图中。临时文件。 I could just name the tmp files systematically, say after each server, and then access each feel assuming it has the server's name (or whatever naming convention I use to generate the tmp files). 我可以系统地命名tmp文件,例如在每个服务器之后命名,然后访问每个感觉,并假设它具有服务器的名称(或用于生成tmp文件的任何命名约定)。

What I really need is a way to do this more elegantly by using the gnuplott mechanism - instead of having to spend the memory and computational resources on writing - then parsing - temp files. 我真正需要的是一种使用gnuplott机制更优雅地实现此目的的方法-而不是必须花费内存和计算资源来编写-然后解析-临时文件。

The tool this is part of is very costly in terms of computation and memory for other things the program is doing - so it would be MUCH better to avoid the process of -- Parse File - create temp files - plot temp file data for each file - destroy files 这是该工具的一部分,它在程序执行其他操作方面的计算和内存成本非常高-因此最好避免以下过程-解析文件-创建临时文件-为每个文件绘制临时文件数据-销毁文件

Let me know of any questions - or I need to explain better - I understand this a very long and specific question. 让我知道任何问题-或者我需要更好地解释-我理解这是一个非常长而具体的问题。 I have read through the documentation (which is not great) among other sources - and frankly I am going forward with the tmp file approach until a better solution is proposed. 我已经阅读了其他资料中的文档(不是很好),并且坦率地说,我将继续使用tmp文件方法,直到提出更好的解决方案为止。

This is literally the first question I have ever asked on stackoverflow! 从字面上看,这是我曾经问过的第一个关于stackoverflow的问题!

Thank you. 谢谢。

I haven't done such thing and haven't investigated your issue but just in case it helps: 我没有做过这样的事情,也没有调查过您的问题,以防万一它有帮助:

1) I would pursue more the ternary operator. 1)我会追求更多的三元运算符。 Other people with similar problem managed to do it successfully: gnuplot conditional plotting: plot col A:col B if col C == x or http://kevinhise.blogspot.com/2011/11/gnuplot-rows-conditionally-depending.html 遇到类似问题的其他人也成功地做到了这一点: gnuplot条件绘图:如果col C == xhttp://kevinhise.blogspot.com/2011/11/gnuplot-rows-conditionally-depending, 则打印col A: colB。 html

2) I agree that temp files would be more demanding in terms of disk space but computationally? 2)我同意临时文件在磁盘空间方面的要求会更高,但在计算方面会更高? Not necessarily much, better to check. 不一定很多,最好检查一下。

This is literally the first answer I have ever given on stackoverflow. 从字面上看,这是我对stackoverflow给出的第一个答案。 You have probably checked the links before but in case anyone peeks at this question and wouldn't have problems with ternary operator pointed by you (the nature of which I don't understand after your laconic description), they may be helpful. 您可能之前已经检查了链接,但是如果有人偷看了这个问题,并且对您指出的三元运算符没有问题(在您简洁的描述之后我不理解其性质),它们可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM