Gnuplot:在Y轴上绘制直方图

时间:2013-12-05 18:46:25

标签: matplotlib plot gnuplot

我正在尝试为以下数据绘制直方图:

<text>,<percentage> 
--------------------
"Statement A",50%
"Statement B",20%
"Statement C",30%

我使用set datafile separator ","来获取相应的列。该图应具有X轴上的百分比和Y轴上的语句(完整字符串)。所以每个直方图都是水平的。

我怎么能在gnuplot中这样做? 还是有其他工具可用于绘制好的矢量图像?

2 个答案:

答案 0 :(得分:3)

gnuplot histogramboxes绘图样式适用于垂直框。要获得水平框,您可以使用boxxyerrorbars

对于作为y标签的字符串,我使用yticlabels并将框放在y值0,1和2处(根据数据文件中的行,使用{{1}访问})。

我让gnuplot将第二列视为数值,将$0关闭。稍后会在xtics的格式化中添加它:

%

版本4.6.4的结果是:

enter image description here

答案 1 :(得分:0)

@ Christoph 谢谢。您的回答对我有所帮助。

@ Slayer 关于使用 gnuplot v5.2补丁程序级别6 并使用@ Christoph 提供的示例添加标签的问题。

@ Slayer >

示例代码:

# set the data file delimiter
set datafile separator ','

# set the x-axiz labels to show percentage
set format x '%g%%'

# set the x-axis min and max range
set xrange [ 0 : 100]

# set the style of the bars
set style fill solid

# set the textbox style with a blue line colour
set style textbox opaque border lc "blue"

# plot the data graph and place the labels on the bars
plot 'plotv.txt' using ($2*0.5):0:($2*0.5):(0.3):yticlabels(1) with boxxyerrorbars t '', \
     ''          using 2:0:2 with labels center boxed notitle column

提供的示例数据:(plotv.txt)

<text>,<percentage> 
--------------------
"Statement A",50%
"Statement B",20%
"Statement C",30%

参考:

  1. gnuplot 5.2 demo sample - textbox和相关的sample data