Matplotlib Gnuplot:在Y轴上绘制直方图

Matplotlib Gnuplot:在Y轴上绘制直方图,matplotlib,plot,gnuplot,Matplotlib,Plot,Gnuplot,我正试图为以下数据绘制直方图: <text>,<percentage> -------------------- "Statement A",50% "Statement B",20% "Statement C",30% , -------------------- “声明A”,50% “报表B”,20% “报表C”,30% 我使用设置数据文件分隔符“,”来获得相应的列。绘图应在X轴上显示百分比,在Y轴上显示语句(完整字符串)。所以每个直方图都是水平的 我如何在gn

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

<text>,<percentage> 
--------------------
"Statement A",50%
"Statement B",20%
"Statement C",30%
,
--------------------
“声明A”,50%
“报表B”,20%
“报表C”,30%
我使用
设置数据文件分隔符“,”
来获得相应的列。绘图应在X轴上显示百分比,在Y轴上显示语句(完整字符串)。所以每个直方图都是水平的

我如何在gnuplot中做到这一点?
或者有其他工具可以绘制好的矢量图像吗?

gnuplot
直方图和
打印样式用于垂直框。要获取水平框,可以使用
boxxyerrorbars

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

我让gnuplot将第二列视为数值,这将去掉
%
。稍后将在xtics的格式中添加:

set datafile separator ','
set format x '%g%%'
set style fill solid
plot 'data.txt' using ($2*0.5):0:($2*0.5):(0.4):yticlabels(1) with boxxyerrorbars t ''
版本4.6.4的结果是:


@克里斯托夫谢谢。你的回答帮助了我

@Slayer关于您使用gnuplot v5.2 patchlevel 6和@Christoph提供的示例添加标签的问题

示例代码:

# 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)

,
--------------------
“声明A”,50%
“报表B”,20%
“报表C”,30%
参考资料:

# 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
  • 以及相关的

  • 谢谢克里斯托夫的帮助。还有一件事,我怎样才能在每个框的右边打印百分比呢。在对应框的侧面说37%。