Gnuplot:如何在条形图中的每个条形图的顶部显示实际值?
Gnuplot: How to display actual values on top of each bar in a bar-plot?
gnuplot 初学者。本质上,我对主题所说的感兴趣。我已经有一个在渲染条形方面起作用的机制,我只想在每个条形的顶部添加标签值:
我在名为 'data.dat' 的文件中有以下数据:
1,Json,457054
2,MessagePack,685440
3,Cbor,1273723
我使用以下 gnuplot 配置文件 'plot.gp':
##
# file_path - path to the file from which the data will be read
# graphic_file_name - the graphic file name to be saved
# y_label - the desired label for y axis
# y_range_min - minimum range for values in y axis
# y_range_max - maximum range for values in y axis
# column_1 - the first column to be used in plot command
# column_2 - the second column to be used in plot command
##
# graphic will be saved as 800x600 png image file
set terminal png
# allows grid lines to be drawn on the plot
set grid
# setting the graphic file name to be saved
set output graphic_file_name
# the graphic's main title
set title "Comparison"
# since the input file is a CSV file, we need to tell gnuplot that data fields are separated by comma
set datafile separator ","
# disable key box
set key off
# label for y axis
set ylabel y_label
# range for values in y axis
set yrange[y_range_min:y_range_max]
# to avoid displaying large numbers in exponential format
set format y "%.0f"
# vertical label for x values
set xtics rotate
# set boxplots
set style fill solid
set boxwidth 0.5
# plot graphic for each line of input file
plot for [i=0:*] file_path every ::i::i using column_1:column_2:xtic(2) with boxes
我 运行 以下 gnuplot 命令:
gnuplot \
-e "file_path='data.dat' " \
-e "graphic_file_name='output.png' " \
-e "y_label='y' " \
-e "y_range_min='0000000'' " \
-e "y_range_max='1500000' " \
-e "column_1=1 " \
-e "column_2=3 " \
plot.gp
我不知道如何使用 .gp 文件底部的 'with labels'。任何帮助表示赞赏。
这里还有一个例子。无需在 for 循环中执行此操作。您可以使用伪列 0(检查 help pseudocolumns
)和 lc var
(检查 help linecolor variable
)来设置颜色。
代码:
### plot with boxes and labels
reset session
$Data <<EOD
1,Json,457054
2,MessagePack,685440
3,Cbor,1273723
EOD
set datafile separator comma
set style fill solid 0.3
set key noautotitle
set xrange[0.5:3.5]
set yrange[0:]
set format y "%.0f"
set grid x,y
set boxwidth 0.8 relative
plot $Data u 1:3:([=10=]+1):xtic(2) w boxes lc var, \
'' u 1:3:3 w labels offset 0,0.7
### end of code
结果:
gnuplot 初学者。本质上,我对主题所说的感兴趣。我已经有一个在渲染条形方面起作用的机制,我只想在每个条形的顶部添加标签值:
我在名为 'data.dat' 的文件中有以下数据:
1,Json,457054
2,MessagePack,685440
3,Cbor,1273723
我使用以下 gnuplot 配置文件 'plot.gp':
##
# file_path - path to the file from which the data will be read
# graphic_file_name - the graphic file name to be saved
# y_label - the desired label for y axis
# y_range_min - minimum range for values in y axis
# y_range_max - maximum range for values in y axis
# column_1 - the first column to be used in plot command
# column_2 - the second column to be used in plot command
##
# graphic will be saved as 800x600 png image file
set terminal png
# allows grid lines to be drawn on the plot
set grid
# setting the graphic file name to be saved
set output graphic_file_name
# the graphic's main title
set title "Comparison"
# since the input file is a CSV file, we need to tell gnuplot that data fields are separated by comma
set datafile separator ","
# disable key box
set key off
# label for y axis
set ylabel y_label
# range for values in y axis
set yrange[y_range_min:y_range_max]
# to avoid displaying large numbers in exponential format
set format y "%.0f"
# vertical label for x values
set xtics rotate
# set boxplots
set style fill solid
set boxwidth 0.5
# plot graphic for each line of input file
plot for [i=0:*] file_path every ::i::i using column_1:column_2:xtic(2) with boxes
我 运行 以下 gnuplot 命令:
gnuplot \
-e "file_path='data.dat' " \
-e "graphic_file_name='output.png' " \
-e "y_label='y' " \
-e "y_range_min='0000000'' " \
-e "y_range_max='1500000' " \
-e "column_1=1 " \
-e "column_2=3 " \
plot.gp
我不知道如何使用 .gp 文件底部的 'with labels'。任何帮助表示赞赏。
这里还有一个例子。无需在 for 循环中执行此操作。您可以使用伪列 0(检查 help pseudocolumns
)和 lc var
(检查 help linecolor variable
)来设置颜色。
代码:
### plot with boxes and labels
reset session
$Data <<EOD
1,Json,457054
2,MessagePack,685440
3,Cbor,1273723
EOD
set datafile separator comma
set style fill solid 0.3
set key noautotitle
set xrange[0.5:3.5]
set yrange[0:]
set format y "%.0f"
set grid x,y
set boxwidth 0.8 relative
plot $Data u 1:3:([=10=]+1):xtic(2) w boxes lc var, \
'' u 1:3:3 w labels offset 0,0.7
### end of code
结果: