gnuplot 直方图:负值下降而不是上升
gnuplot histogram : negative values go down instead go up
我尝试使用 gnuplot 生成直方图。我有正面和负面的价值观。正值位于图表顶部,而负值位于图表底部。
我想改变上升和下降的基础
例如从 0 到 -100。
也许,这样做不是很好的图形类型?
我已经试过了:
gnuplot -e "set terminal png size 20000, 1500; set yrange [-100:*]; set title 'VU meter 0'; set style data histogram; set style histogram clustered gap 1; set style fill solid 1 noborder; plot 'testVUmeter0.tsv' using 2:xticlabels(1)" > out.png
谢谢
您可以在每个点计算一个新的 y 值,同时考虑一些想要的偏移量。例如,设置 bot=-20
以给出 -20 的底部 y 值,您可以参考 (-bot)
将 -5 转换为高于 0 的 -5-(-20)=
15`。
set terminal png size 400,300
set output "out.png"
set style data histogram
set style histogram clustered gap 1
set style fill solid 1 noborder
bot=-20
set yrange [0:*]
set ytics ("-10" -10-bot, "0" 0-bot, "10" 10-bot, "20" 20-bot, "30" 30-bot)
plot "data" using (()-bot):xticlabels(1) notitle, \
"" using 0:(+3-bot):(sprintf("%d",)) with labels notitle
数据为
1 33
2 44
3 22
4 -12
给出剧情:
据我所知,绘图样式 histogram
和 with boxes
始终从 y=0 开始。
假设我正确理解了你的问题,你想改变这个零水平,例如到-100。
只要您不需要高级直方图样式而只需要简单的框,一种可能的解决方案就是使用绘图样式 with boxxyerror
。与@meuh 的解决方案相比,在这里,gnuplot 会自动处理 y-tics。
代码:
### shift zero for boxes
reset session
$Data <<EOD
A -20
B -140
C 100
D -340
E +250
F 0
EOD
myOffset = -100
myWidth = 0.8
set style fill solid 1.0
set arrow 1 from graph 0, first myOffset to graph 1, first myOffset nohead ls -1
set style textbox opaque
plot $Data u 0:2:([=10=]-myWidth/2.):([=10=]+myWidth/2.):(myOffset):2:xtic(1) w boxxyerror notitle, \
'' u 0:2:2 w labels boxed notitle
### end of code
结果:
我尝试使用 gnuplot 生成直方图。我有正面和负面的价值观。正值位于图表顶部,而负值位于图表底部。
我想改变上升和下降的基础
也许,这样做不是很好的图形类型?
我已经试过了:
gnuplot -e "set terminal png size 20000, 1500; set yrange [-100:*]; set title 'VU meter 0'; set style data histogram; set style histogram clustered gap 1; set style fill solid 1 noborder; plot 'testVUmeter0.tsv' using 2:xticlabels(1)" > out.png
谢谢
您可以在每个点计算一个新的 y 值,同时考虑一些想要的偏移量。例如,设置 bot=-20
以给出 -20 的底部 y 值,您可以参考 (-bot)
将 -5 转换为高于 0 的 -5-(-20)=
15`。
set terminal png size 400,300
set output "out.png"
set style data histogram
set style histogram clustered gap 1
set style fill solid 1 noborder
bot=-20
set yrange [0:*]
set ytics ("-10" -10-bot, "0" 0-bot, "10" 10-bot, "20" 20-bot, "30" 30-bot)
plot "data" using (()-bot):xticlabels(1) notitle, \
"" using 0:(+3-bot):(sprintf("%d",)) with labels notitle
数据为
1 33
2 44
3 22
4 -12
给出剧情:
据我所知,绘图样式 histogram
和 with boxes
始终从 y=0 开始。
假设我正确理解了你的问题,你想改变这个零水平,例如到-100。
只要您不需要高级直方图样式而只需要简单的框,一种可能的解决方案就是使用绘图样式 with boxxyerror
。与@meuh 的解决方案相比,在这里,gnuplot 会自动处理 y-tics。
代码:
### shift zero for boxes
reset session
$Data <<EOD
A -20
B -140
C 100
D -340
E +250
F 0
EOD
myOffset = -100
myWidth = 0.8
set style fill solid 1.0
set arrow 1 from graph 0, first myOffset to graph 1, first myOffset nohead ls -1
set style textbox opaque
plot $Data u 0:2:([=10=]-myWidth/2.):([=10=]+myWidth/2.):(myOffset):2:xtic(1) w boxxyerror notitle, \
'' u 0:2:2 w labels boxed notitle
### end of code
结果: