gnuplot 直方图:如何将值放在条形顶部

发布于 2024-10-28 01:24:08 字数 489 浏览 0 评论 0原文

我有以下数据:

1   3215
2   321
...
31_60   59
60+   32

我想使用 gnuplot 生成直方图并将 bar 的值放在其顶部。

这是我尝试创建直方图的 gnuplot 命令:

set style data histogram
set xtics rotate
plot 'file.dat' using 2:xtic(1)

有人能告诉我如何在生成的条形顶部添加值吗?

我找到了以下链接相关的直方图(http://gnuplot-tricks .blogspot.com/2009/10/more-on-histograms.html),但没有明白它到底在做什么。

I have the following data:

1   3215
2   321
...
31_60   59
60+   32

I would like to generate histogram using gnuplot and put the value of bar on top of it.

Here is the gnuplot command I tried to create histogram:

set style data histogram
set xtics rotate
plot 'file.dat' using 2:xtic(1)

Can someone tell me how to add values on top of the bars generated?

I found the following link related histogram (http://gnuplot-tricks.blogspot.com/2009/10/more-on-histograms.html), but didnt get what its doing exactly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

挽清梦 2024-11-04 01:24:08

使用 0 与 xtic() 配合得很好。

plot 'file.dat' using 2:xtic(1) with histogram, '' using 0:2:2 with labels

using 0 works well with xtic().

plot 'file.dat' using 2:xtic(1) with histogram, '' using 0:2:2 with labels
孤独患者 2024-11-04 01:24:08

将此作为示例数据文件 Data.dat

1 10
2 20
3 15
4 16
5 19
6 5

您可以运行此脚本来显示框及其上方该框的相应值:

set key off
plot 'Data.dat' with boxes fill pattern 1, '' u 1:($2 + 0.5):($2) with labels

注意 u 1:($2 + 0.5): ($2) 其中 0.5 指定该值高于框的程度。

With this as some sample data file Data.dat:

1 10
2 20
3 15
4 16
5 19
6 5

You could run this script to display boxes and the corresponding value of that box above it:

set key off
plot 'Data.dat' with boxes fill pattern 1, '' u 1:($2 + 0.5):($2) with labels

Notice the u 1:($2 + 0.5):($2) where the 0.5 specifies how much the value is above the box.

烟织青萝梦 2024-11-04 01:24:08

假设我有以下 data.dat 文件,

"Method 1"              99.63               9.13                
"Method 2"              97.35               10.85               
"Method 3"              97.16               13.76                        
"Method 4"              95.16               15.56

我可以使用 gnuplot 中的以下命令行获取以下条形图,其值位于条形顶部:

reset

set terminal postscript eps size 3.5,2.62 enhanced color font 'Helvetica,20'  lw 2
set output 'StackOverflow.eps'

set style fill solid 1.00
set style histogram clustered gap 1
set style data histograms
set yrange [0:120] 
set xtics  norangelimit font ",8"
set ytics  norangelimit font ",8"
set xlabel "X-Axis" font "Helvetica,10"
set ylabel "Y-Axis" font "Helvetica,10"
set key font ",8"
set key width -8

xoffset=0.17
yoffset=0.03

plot 'data.dat' using 2:xtic(1) with histogram  title "Parameter 1", \
     '' u 3 with histogram title "Parameter 2", \
     '' u 0:2:2  with labels font "Helvetica,10" offset -0.9,0.5 title " ", \
     '' u 0:3:3  with labels font "Helvetica,10" offset 0.9,0.5 title " "

结果:

条形图,值位于条形顶部

Suppose I have the following data.dat file

"Method 1"              99.63               9.13                
"Method 2"              97.35               10.85               
"Method 3"              97.16               13.76                        
"Method 4"              95.16               15.56

I can get the following bar graph plot with values at the top of the bar with following line of commands in gnuplot:

reset

set terminal postscript eps size 3.5,2.62 enhanced color font 'Helvetica,20'  lw 2
set output 'StackOverflow.eps'

set style fill solid 1.00
set style histogram clustered gap 1
set style data histograms
set yrange [0:120] 
set xtics  norangelimit font ",8"
set ytics  norangelimit font ",8"
set xlabel "X-Axis" font "Helvetica,10"
set ylabel "Y-Axis" font "Helvetica,10"
set key font ",8"
set key width -8

xoffset=0.17
yoffset=0.03

plot 'data.dat' using 2:xtic(1) with histogram  title "Parameter 1", \
     '' u 3 with histogram title "Parameter 2", \
     '' u 0:2:2  with labels font "Helvetica,10" offset -0.9,0.5 title " ", \
     '' u 0:3:3  with labels font "Helvetica,10" offset 0.9,0.5 title " "

Result:

Bar graph Plot with values at top of the bar

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文