手动使用xtics的Gnuplot直方图

时间:2014-04-29 16:42:08

标签: gnuplot histogram

我有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轴上制作标签,并且所有条形图都有相同的颜色。

这是我当前的输出:

enter image description here

2 个答案:

答案 0 :(得分:3)

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

像这样安排你的数据文件(比如在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

enter image description here

答案 1 :(得分:-1)

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