【问题标题】:Gnuplot histogram with xtics manually手动使用 xtics 的 Gnuplot 直方图
【发布时间】:2014-04-29 16:42:08
【问题描述】:

我对 gnuplot 直方图有疑问。 我有文件数据并想手动创建 xtics。 这是我的数据:

5   10  15  20  25  30  35

这是我的 gnuplot:

set terminal pngcairo enhanced font "arial,10" fontscale 1.0 size 500, 350 
set output 'histograms.2.png'
set boxwidth 0.9 absolute
set style fill   solid 1.00 border lt -1
set key inside right top vertical Right noreverse noenhanced autotitles nobox
set style histogram clustered gap 1 title  offset character 0, 0, 0
set datafile missing '-'
set style data histograms
set xtics border in scale 0,0 nomirror rotate by -45  offset character 0, 0, 0 autojustify
set xtics  norangelimit font ",8"
set title "testing" 
plot 'histogram2.dat'   using($0):xtic("sdaf")  title "Legend 1", \
                        ''  using($2):xtic("sdasa")         title "Legend 2", \
                        ''  using($3):xtic("sdSs")      title "Legend 3",  \
                        ''  using($4)       title "Legend 4",  \
                        ''  using($5)       title "Legend 5",  \
                        ''  using($6)       title "Legend 6",  \
                        ''  using($7)       title "Legend 7"  

在我当前的图表中,第一行不能出现在图表中。 我还想在 x 轴上制作标签,并且所有条形都具有相同的颜色。

这是我当前的输出:

【问题讨论】:

    标签: gnuplot histogram


    【解决方案1】:

    我希望我能理解你的问题。您或许可以执行以下操作:

    像这样排列你的数据文件(比如在 file1.dat 中):

    "Legend 1" 5
    "Legend 2" 10
    "Legend 3" 15
    "Legend 4" 20
    "Legend 5" 25
    "Legend 6" 30
    "Legend 7" 35
    

    然后在您的 Gnuplot 脚本中添加以下内容:

    file1 = "file1.dat"
    set style data histogram 
    set style histogram clustered gap 1
    
    set ylabel "Ylabel" font ",18" offset character 2.5,0,0
    set grid y
    set yrange[0:40]
    set xtics border in scale 0,0 nomirror rotate by 90  offset character -1, -4, 0
    set ytics (0, 10, 20, 30, 40) 
    
    set boxwidth 0.9 absolute
    
    set style fill transparent solid 0.8 noborder
    set key outside right top vertical Left
    
    plot newhistogram , file1 u 2:xtic(1) t "My Legend" lc rgbcolor "blue" lt 1
    

    【讨论】:

    • x 轴仍未出现在我的图表中。
    • 你还需要整理你的数据文件,就像我上面的解决方案中给出的那样。
    • 我复制粘贴了数据文件和 .gnu 文件,但我的 xtic 标签仍然没有显示任何内容。你设置了哪个术语?
    • 在 OP 中的 pngcairo
    【解决方案2】:

    也许问题出在这里 -->using($0):xtic("sdaf") title "Legend 1", 将其设置为 $1 而不是 $0

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-30
      • 1970-01-01
      • 2011-01-29
      • 1970-01-01
      • 1970-01-01
      • 2013-07-28
      相关资源
      最近更新 更多