2个月之间的Gnuplot百分比差异 [英] Gnuplot percentage difference between 2 months

查看:111
本文介绍了2个月之间的Gnuplot百分比差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从5年的恶意软件数据中提取了一个csv文件,其中日期有2列,每个日期的ip都有1个或多个ips示例

i have a csv file from 5 year malware data collected there are 2 columns the dates and the ips every date have 1 or more ips example

1/5/2013 12.234.123
1/5/2013 45.123.566
1/5/2013 100.546.12
1/6/2013 42.153.756
3/4/2014 75.356.258 etc... (every day for 5 years)

现在我正在尝试获取每个月示例之间的百分比差异:

now i am trying to get the percentage difference between every month example:

November 2014 - 10%
December 2014 - 15%

我试图将百分比放在y轴和x2轴上,但是即时通讯出现了一些疯狂的结果,我是gnuplot的新手,即时通讯仍然在学习,这里是我现在拥有的代码:

i tried to put the percentage on y axis and in x2 axis but im getting some crazy results i am new to gnuplot and im still learning it here is the code i have right now:

set title 'Results Per Month'
set xlabel 'Date'
set ylabel 'Percentage'
set terminal png size 2800,900
set datafile sep ','
set xdata time

set timefmt '%Y/%m/%d'
set xrange['2009/3/22':'2014/12/02']
set xtics 30*24*60*60
set format x '%Y/%m'

set autoscale x2fix
set x2tics 
set x2range[0:*]
set format x2 "%g %%"

set xtics nomirror rotate by -90
set grid ytics xtics
set ytics 10
set yrange [0:*]
set term png
set output 'file.png'

plot 'export.csv' using (timecolumn(1) - (tm_mday(timecolumn(1))-1)*24*60*60):(1) smooth frequency w lp pt 7 ps 2 notitle, \
'' using (($1-$2)/$1*100):x2ticlabels(2) axes x2y1 with points ps 2 lw 2

推荐答案

我建议您使用一些外部脚本进行此类预处理(您也可以即时执行此操作).是的,您可以分两步在gnuplot中执行此操作,但会变得相当复杂,并且需要对gnuplot有更深入的了解.

I would suggest you to use some external script for such kind of preprocessing (you can also do this on-the-fly). Yes, you can do this in gnuplot in two steps, but can become quite complicated and requires some more profound knowledge of gnuplot.

这是一个有效的脚本,但我不会详细介绍实际实现的许多不同方面:

Here is a working script, but I won't go into detail about the many different aspects of the actual implementation:

set xdata time
set timefmt '%Y/%m/%d'
set datafile separator ','

set table 'temporaryfile.dat'
set format x '%Y/%m/%d'
plot 'export.csv' using (timecolumn(1) - (tm_mday(timecolumn(1))-1)*24*60*60):(1) smooth frequency 
unset table

set y2tics
set ytics nomirror
set timefmt '"%Y/%m/%d"'
set format x '%b %Y'
set xtics rotate by 90 right

set datafile separator white
set yrange[0:*]
x0=x1=0
plot 'temporaryfile.dat' using 1:(strcol(3) eq "i" ? $2 : 1/0) w lp pt 7 ps 2 title 'IP count', \
     '' using 1:(x1=x0, x0=$2, strcol(3) eq "i" ? ($0 == 0 || x0 == 0 ? 0 : (x0-x1)/x0 * 100.0) : 1/0) axes x1y2 w lp title 'percentual change'

基本上,首先将smooth frequency的结果数据绘制到第二个数据文件中.然后,您可以对此进行绘制,并绘制出百分比的计算.

Basically, first you plot the result data of smooth frequency into a second data file. Then you can plot this, and to the calculations for the percentages.

请注意,我使用的时间格式与您的测试数据(以及上一个问题的数据)相对应,与您的脚本中的内容不对应!请注意这一点.

Please note, that I used a timeformat which corresponds to your test data (and the data of your previous question), which doesn't correspond with what you have in your script! Please pay attention to this.

还请注意,必须在实际图之前的timefmt加上引号,并在tmp.dat中的日期周围写上.

Also note, that the timefmt before the actual plot must be extended by quote signs which are written around the dates in tmp.dat.

最后,必须使用strcol(3) eq 'i'来避免gnuplot错误,该错误会导致最后一行写入无效数据.

Finally, the strcol(3) eq 'i' is necessary to circumvent a gnuplot bug, which causes a last line to be written with invalid data.

这篇关于2个月之间的Gnuplot百分比差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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