Question

I have problems with gnuplot histogram. I have file data and want to create xtics manually. Here my data:

5   10  15  20  25  30  35

Here my 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"  

In my current graphs, the first row can not appear at the graphs. Also I want to make label at x axis and also have the same colors for all bar.

here my current output:

enter image description here

Was it helpful?

Solution

I hope I understand your question. You can perhaps do the following:

Arrange your data file like this (say in file1.dat):

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

Then have the following in your Gnuplot script:

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

OTHER TIPS

Maybe the problem is here -->using($0):xtic("sdaf") title "Legend 1", set it to $1 instead of $0

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top