如何绘制分类、累积和时间相关的数据?

huangapple go评论136阅读模式
英文:

How do I chart categorical, cumulative, and time-dependent data?

问题

我有一堆随时间变化的数据,这些数据不减少且右连续,总是涉及某个类别,可以重复。我正在寻找一种类似于可变宽度的条形图,或级联图,但从右侧翻转的图表。例如,

set term postscript eps enhanced
set output "so.eps"
$Data <<EOD
# date	source	reg	sic	pic	total
2000-07-25	2000glider	C-FJSN	8	0	216
2000-07-28	2000glider	C-FJSN	10	0	226
2000-07-28	2000glider	C-FJSN	11	0	237
2000-07-28	2000glider	C-GCLB	4	0	241
2000-07-29	2000glider	C-GCLY	3	0	244
2000-07-29	2000glider	C-GCLY	2	0	246
2000-07-29	2000glider	C-GCLY	17	0	263
2000-07-30	2000glider	C-GCLB	15	0	278
2000-07-30	2000glider	C-GCLB	0	13	291
2000-07-30	2000glider	C-GCLK	11	0	302
2000-07-30	2000glider	C-FJSN	0	16	318
2000-07-30	2000glider	C-GCLB	0	10	328
2000-08-02	2000glider	C-GQRT	0	13	341
2000-08-04	2000glider	C-GCLY	0	11	352
2000-08-05	2000glider	C-GCLB	12	0	364
2000-08-05	2000glider	C-GCLB	0	12	376
2000-08-06	2000glider	C-GCLB	0	11	387
2000-08-07	2000glider	C-GFMB	0	12	399
2000-08-07	2000glider	C-GCMB	0	11	410
2000-08-08	2000glider	C-GCLK	0	12	422
2000-08-09	2000glider	C-GCLB	14	0	436
2000-08-09	2000glider	C-GCLB	0	9	445
2000-08-10	2000glider	C-GCLL	0	10	455
EOD
set monochrome
set xdata time
set timefmt "%Y-%m-%d"
set xtics format "%Y-%m-%d" rotate by -30
set ylabel "hours"
set grid
unset key
unset border
plot $Data using 1:($6/60) with fillsteps lw 2, \
 $Data using 1:($6/60):3 with labels

这给出了以下结果:

如何绘制分类、累积和时间相关的数据?

我正在尝试创建类似于累积分布函数的图表,其中在这种情况下,小时会逐渐累加。我希望曲线在左侧达到零,在右侧达到最大值。标签不是打印出来,而是应该在键中,并与其他连续数据一起从右侧映射到数据。是否有这样的图表,以及如何创建它?

我可以完全控制输入,所以我在考虑可能使用逆变换和旋转会更容易?

英文:

I have a bunch of time-dependent data, non-decreasing and right-continuous, always with come category involved, that can be repeated. I am looking for a sort of a variable width-bar chart, or cascade chart, flipped on it's side, from the right. For example,

set term postscript eps enhanced
set output &quot;so.eps&quot;
$Data &lt;&lt;EOD
# date	source	reg	sic	pic	total
2000-07-25	2000glider	C-FJSN	8	0	216
2000-07-28	2000glider	C-FJSN	10	0	226
2000-07-28	2000glider	C-FJSN	11	0	237
2000-07-28	2000glider	C-GCLB	4	0	241
2000-07-29	2000glider	C-GCLY	3	0	244
2000-07-29	2000glider	C-GCLY	2	0	246
2000-07-29	2000glider	C-GCLY	17	0	263
2000-07-30	2000glider	C-GCLB	15	0	278
2000-07-30	2000glider	C-GCLB	0	13	291
2000-07-30	2000glider	C-GCLK	11	0	302
2000-07-30	2000glider	C-FJSN	0	16	318
2000-07-30	2000glider	C-GCLB	0	10	328
2000-08-02	2000glider	C-GQRT	0	13	341
2000-08-04	2000glider	C-GCLY	0	11	352
2000-08-05	2000glider	C-GCLB	12	0	364
2000-08-05	2000glider	C-GCLB	0	12	376
2000-08-06	2000glider	C-GCLB	0	11	387
2000-08-07	2000glider	C-GFMB	0	12	399
2000-08-07	2000glider	C-GCMB	0	11	410
2000-08-08	2000glider	C-GCLK	0	12	422
2000-08-09	2000glider	C-GCLB	14	0	436
2000-08-09	2000glider	C-GCLB	0	9	445
2000-08-10	2000glider	C-GCLL	0	10	455
EOD
set monochrome
set xdata time
set timefmt &quot;%Y-%m-%d&quot;
set xtics format &quot;%Y-%m-%d&quot; rotate by -30
set ylabel &quot;hours&quot;
set grid
unset key
unset border
plot $Data using 1:($6/60) with fillsteps lw 2, \
$Data using 1:($6/60):3 with labels

Which gives,

如何绘制分类、累积和时间相关的数据?

I'm trying to create like a cumulative distribution function, where hours, in this case, are added. I want the line to go to zero on the left and the maximum value on the right. The labels, instead of printing, should be in the key and mapped to the data, grouped with other consecutive data, from the right. Is there such a plot, and how to I create it?

I have full control over the input, so I was thinking maybe an inverse-transform and rotate would be easier?

答案1

得分: 2

抱歉,我无法识别您的代码内容。请您提供您需要翻译的文字,我会尽力协助您。

英文:

Not sure if I fully understood all your points correctly.
Maybe the following script might bring you closer to what you want.

Update:

If you want color bars for intervals then you could use the plotting style with boxxyerror (check help boxxy).

  • with boxxy requires either 4 or 6 columns. 4 columns would be (x):(y):(dx):(dy) for a box centered at x,y with +/-dx and +/-dy.

  • sum up your durations which are either in column 4 or 5 in the variable total. No need for column 6.

  • the difference dx=43200 (i.e. half a day in seconds)

There are different ways of plottings steps.

Script:

### cumulative plot with color code
reset session
$Data &lt;&lt;EOD
# date  source  reg sic pic total
2000-07-25  2000glider  C-FJSN  8   0   216
2000-07-28  2000glider  C-FJSN  10  0   226
2000-07-28  2000glider  C-FJSN  11  0   237
2000-07-28  2000glider  C-GCLB  4   0   241
2000-07-29  2000glider  C-GCLY  3   0   244
2000-07-29  2000glider  C-GCLY  2   0   246
2000-07-29  2000glider  C-GCLY  17  0   263
2000-07-30  2000glider  C-GCLB  15  0   278
2000-07-30  2000glider  C-GCLB  0   13  291
2000-07-30  2000glider  C-GCLK  11  0   302
2000-07-30  2000glider  C-FJSN  0   16  318
2000-07-30  2000glider  C-GCLB  0   10  328
2000-08-02  2000glider  C-GQRT  0   13  341
2000-08-04  2000glider  C-GCLY  0   11  352
2000-08-05  2000glider  C-GCLB  12  0   364
2000-08-05  2000glider  C-GCLB  0   12  376
2000-08-06  2000glider  C-GCLB  0   11  387
2000-08-07  2000glider  C-GFMB  0   12  399
2000-08-07  2000glider  C-GCMB  0   11  410
2000-08-08  2000glider  C-GCLK  0   12  422
2000-08-09  2000glider  C-GCLB  14  0   436
2000-08-09  2000glider  C-GCLB  0   9   445
2000-08-10  2000glider  C-GCLL  0   10  455
EOD
# get a unique list from datablock
addToList(list,col) = list.( strstrt(list,&#39;&quot;&#39;.strcol(col).&#39;&quot;&#39;) &gt; 0 ? \
&#39;&#39; : &#39; &quot;&#39;.strcol(col).&#39;&quot;&#39;)
Uniqs = &#39;&#39;
stats $Data u (Uniqs=addToList(Uniqs,3)) nooutput
Uniq(i)     = word(Uniqs,i)
getIndex(s) = sum [_i=1:words(Uniqs)] s eq word(Uniqs,_i) ? _i : 0
myTimeFmt = &quot;%Y-%m-%d&quot;
set format x myTimeFmt timedate
set xtics format myTimeFmt rotate by -30
set ylabel &quot;hours&quot;
set format y &quot;%tH:%tM&quot; timedate
set grid
set key out reverse Left noautotitle
set style fill solid 0.5
plot  total=0 $Data u (timecolumn(1,myTimeFmt)):(dy=($4+$5)*60,total=total+dy) w steps lc &quot;black&quot; dt 3, \
total=0 &#39;&#39;    u (timecolumn(1,myTimeFmt)):(dy=($4+$5)*60,total=total+dy,total-dy/2.): \
(43200):(dy/2.):(getIndex(strcol(3))) w boxxy lc var, \
for [i=1:words(Uniqs)] keyentry w boxxy lc i ti Uniq(i)
### end of script

Result:

如何绘制分类、累积和时间相关的数据?

huangapple
  • 本文由 发表于 2023年2月16日 05:44:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/75465717.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定