如何用诸如“< text>"之类的线来绘制数据< datetime>&quot ;,加上gnuplot吗? [英] How to plot data with lines like "<text> <datetime>", with gnuplot?

查看:86
本文介绍了如何用诸如“< text>"之类的线来绘制数据< datetime>&quot ;,加上gnuplot吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据是典型的类似CSV的文本,每行包括两列,第一列是文本,第二列是unix时间戳,如下所示:

My data is a typical CSV-like text where each line consists of two columns where the first is text and the second a unix timestamp, as follows:

Mom 1441008169
Dad 1442516527
Ken 1441783871
...
<text> <unix-timestamp>

我想我可以沿时间轴排列数据,在与时间轴对应的x轴上的点处绘制与该行中的文本相对应的颜色的点/形状.充其量我可以用gnuplot告诉我:

I thought I could arrange the data along a timeline, drawing dots/shapes of color corresponding to the text in the line, at a point along the x axis corresponding to the timestamp. At best I got gnuplot to tell me:

line 0: Need using spec for y time data

当我告诉它:

set ydata time
set timefmt "%s"
plot "-"
<data>
EOF

我想使用点,菱形或形状与第一栏中的文本字符串相对应的颜色来绘制图.换句话说,如果我的文本值落在{{Mom," Dad," Ken}集合内,则gnuplot应该绘制与红色的妈妈",绿色的爸爸"和肯"对应的形状以蓝色或类似的方式在沿x轴对应于其各自时间戳记的点处显示.

I want to render a plot using dots, or diamonds or shapes with color corresponding to the text string in first column. In other words, if my text values fall within the set {"Mom", "Dad", "Ken"}, then gnuplot should draw these shapes corresponding to "Mom" in red, "Dad" in green, and "Ken" in blue, or something like that, at points corresponding to their respective timestamps along the x axis.

对我来说,挑战是让gnuplot区分文本字符串.数据可以被认为是例如来自某个人的来电,其中时间戳指示该呼叫的日期和时间,而文本则代表该呼叫的人.我认为将这些数据表示为沿时间线绘制的点/球/菱形/沿时间线的任何不同颜色都是一个好主意.

The challenge for me is to have gnuplot distinguish between the text strings. The data can be thought of as, for instance, incoming calls from a person where the timestamp indicates date and time for the call and text represents the person calling. I thought representing these data as plotted dots/orbs/diamonds/whatever of different color along a time line would be a good idea, visually.

我将如何实现?我可以选择生成某种标识符表,其中唯一的文本字符串均等同于唯一的顺序生成的ID(如果有帮助的话).

How would I achieve that? I can, optionally, generate some sort of identifier table where the unique text strings are each equated to a unique sequential generated ID, if that helps gnuplot.

推荐答案

我想您想要的是这样的东西

I guess what you want is something like this

x轴跨越由数据文件(第二列)指定的时间间隔.每个名称(肯,妈妈,爸爸)都由不同的点类型(pt)和特定的颜色(lc rgb 'color')表示.

The x-axis spans the time interval which is specified by your data file (2nd column). Each name (Ken, Mom, Dad) is represented by a different point type (pt) and a specific colour (lc rgb 'color').

您可以通过以下命令生成此图(假设数据文件的名称为"test"):

You can generate this plot by the following commands (assuming your data file's name is 'test'):

set xdata time
set timefmt "%s"
set format x "%d/%m/%y"
set xtics rotate
unset ytics
set yrange[0:2]

plot 'test' u ($2):(stringcolumn(1) eq "Ken" ? 1 :1/0) w p pt 5 ps 1.5 lc rgb 'blue' t 'Ken',\
    '' u ($2):(stringcolumn(1) eq "Dad" ? 1 :1/0) w p pt 7 ps 1.5 lc rgb 'red' t 'Dad',\
    '' u ($2):(stringcolumn(1) eq "Mom" ? 1 :1/0) w p pt 3 ps 1.5 lc rgb 'green' t 'Mom'

可以通过为pt分配不同的编号来使用不同的点类型. ps指定点的大小.

You can use different point types by assigning different numbers to pt. ps specifies the point size.

我想到的另一种表示形式是: 您可以使用以下方法生成它:

Another representation I came up with is the following: You can generate it with:

plot 'test' u ($2):(1):(stringcolumn(1)) with labels t '',\
 '' u ($2):(0.95) with impulses t ''

我希望这能回答您的问题,这就是您想要的.

I hope this answers your question, and it is what you were looking for.

这篇关于如何用诸如“&lt; text&gt;"之类的线来绘制数据&lt; datetime&gt;&quot ;,加上gnuplot吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆