【问题标题】:Gnuplot: plotting histograms on Y-axisGnuplot:在 Y 轴上绘制直方图
【发布时间】:2013-12-22 20:55:48
【问题描述】:

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

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

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

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

【问题讨论】:

    标签: matplotlib plot gnuplot


    【解决方案1】:

    gnuplot histogramboxes 绘图样式用于垂直框。要获取水平框,您可以使用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 版本的结果是:

    【讨论】:

    • 感谢克里斯托夫的帮助。还有一件事,我怎样才能在每个框的右侧打印百分比。在相应方框的一侧说 37% 之类的内容。
    【解决方案2】:

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

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

    示例代码:

    # 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-15
      • 2021-10-07
      • 1970-01-01
      相关资源
      最近更新 更多