我有一些汽车价格数据,格式为(年份,里程,价格)为(x,y,z):
2018 53313 17590
2017 106000 10000
2017 69294 16495
2015 88000 13995
2017 38968 17732
...
我使用 python 脚本按年份和里程进行排序,并丢弃只有单个数据点的任何年份,最终得到一个 dat 文件,如下所示。我最终根据此处的答案得到了这种格式。
2014 45281 16995
2014 45281 0
2014 89199 15990
2014 89199 0
2014 115585 10500
2014 115585 0
2015 44477 17962
2015 44477 0
2015 77486 14500
2015 77486 0
2015 88000 13995
2015 88000 0
2016 58751 15998
2016 58751 0
2016 75857 14797
2016 75857 0
...
我的 gnuplot 脚本是:
set terminal png size 800,500 enhanced font "Segoe UI,10"
set output "3d.png"
set zrange [9000:20000]
set hidden3d offset 0
# This is close, but doesn't show "fences"
splot for [i=0:15] "3d.dat" index i u 1:2:3 w lines notitle
这很接近,但我希望实现更像本页所示的情节:
我不知道如何达到立体效果。该图表使用的数据系列似乎是一组 z 值,其中 y 值均匀分布 - 但我的 y 值不规则。我可以更改 python 脚本以根据需要重新格式化数据,我只是不知道它需要什么形状才能实现我正在寻找的那种绘图。
一些评论:
smooth uniq
用于按里程对条目进行排序。如果一年内相同里程可能有多个价格,
smooth uniq
将返回平均价格(检查
help smooth
)。
$Sort
并且由于for循环,年份位于由两个空行分隔的子块中
index
寻址(检查
help index
)
with zerrorfill
splot
中旋转如何在 gnuplot 中以 3D 方式旋转 tic 标签?
脚本:(适用于 gnuplot>=5.2.0,2017 年 9 月)
### plot z-fence, here: x: year, y: mileage, z: price
reset session
# create some random test data
set table $Data
plot '+' u (2014+int(rand(0)*7)):(int(rand(0)*9e4+1e4)):(int(rand(0)*4e4+1e4)) w table
unset table
stats $Data u 1 nooutput # find start and end year
y0 = STATS_min
y1 = STATS_max
set key noautotitle
set grid x,y,z
set xyplane relative 0
set border 1+2+4+8+16+32+64+256+512
set style fill solid 0.4
set xlabel "year" rotate parallel offset 0,-0.5 font ",12"
set xtics out offset 0,-0.5
set ylabel "mileage" rotate parallel font ",12"
set ytics out 20000
set zlabel "price" rotate by 90 offset -3,0 font ",12"
set ztics out 10000
set datafile missing NaN
set table $Sort
plot for [y=y0:y1] $Data u ($1==y?$2:NaN):3 smooth uniq
unset table
splot for [y=y0:y1] $Sort index y-y0 u (y):1:2:0:2 w zerrorfill
### end of script
结果: