I try to generate a histogram plot with gnuplot. I have positive and negative values. Positive values go to the top of the chart, but negative values go to the bottom of the chart.. I would like to change the base for go up and go down from 0 to -100 for example.
Maybe, it's not the good type of graphic to do that?
I have tried this:
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
Thanks
You can calculate a new y value at each point, taking into account some wanted offset. For example, setting bot=-20
to give a bottom y value of -20 you can refer to ($2-bot)
to convert, say, -5 to -5-(-20)=
15` above 0.
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 (($2)-bot):xticlabels(1) notitle, \
"" using 0:($2+3-bot):(sprintf("%d",$2)) with labels notitle
with data of
1 33
2 44
3 22
4 -12
gives the plot:
As far as I know the plotting styles histogram
and with boxes
always start at y=0. Assuming I understood your question correctly, you want to shift this zero level eg to -100. As long as you do not need an advanced histogram style but just simple boxes, one possible solution could be to use the plotting style with boxxyerror
. Compared to @meuh's solution, here, gnuplot automatically takes care about the y-tics.
Code:
### 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:($0-myWidth/2.):($0+myWidth/2.):(myOffset):2:xtic(1) w boxxyerror notitle, \
'' u 0:2:2 w labels boxed notitle
### end of code
Result:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.