Skip to content

Instantly share code, notes, and snippets.

@yichao0319
Last active January 25, 2016 03:37
Show Gist options
  • Save yichao0319/7267995 to your computer and use it in GitHub Desktop.
Save yichao0319/7267995 to your computer and use it in GitHub Desktop.
gnuplot:bar
reset
set terminal postscript eps enhanced color 28
# set terminal postscript eps enhanced monochrome 28
# set terminal png enhanced 28 size 800,600
# set terminal jpeg enhanced font helvetica 28
set size ratio 0.7
data_dir = "DATA_DIR"
fig_dir = "FIG_DIR"
file_name = "FILE_NAME"
fig_name = "FIG_NAME"
set output fig_dir.fig_name.".eps"
set xlabel '{/Helvetica=28 X_LABEL}'
set ylabel '{/Helvetica=28 Y_LABEL}'
set xtics nomirror rotate by DEGREE
set ytics nomirror
set tics font "Helvetica,28"
set xrange [X_RANGE_S:X_RANGE_E]
set yrange [Y_RANGE_S:Y_RANGE_E]
set style data histogram
set style histogram cluster gap 1
set style fill solid border -1
set boxwidth 0.9
set style fill pattern 2
# set style fill solid 0.8
set palette color
# set palette gray
# set lmargin 4.5
# set rmargin 5.5
# set bmargin 3.7
# set tmargin 4.4
# set key right top
# set key at 10,5 ## coordinate of right top corner of the legend
# set key Left under reverse horizontal spacing 0.9 samplen 1.5 width -1
set nokey
set style line 1 lc rgb "red" lt 1 lw 1 pt 1 ps 1.5 pi -1 ## +
set style line 2 lc rgb "blue" lt 2 lw 1 pt 2 ps 1.5 pi -1 ## x
set style line 3 lc rgb "#00CC00" lt 1 lw 1 pt 3 ps 1.5 pi -1 ## *
set style line 4 lc rgb "#7F171F" lt 4 lw 1 pt 4 ps 1.5 pi -1 ## box
set style line 5 lc rgb "#FFD800" lt 3 lw 1 pt 5 ps 1.5 pi -1 ## solid box
set style line 6 lc rgb "#000078" lt 6 lw 1 pt 6 ps 1.5 pi -1 ## circle
set style line 7 lc rgb "#732C7B" lt 7 lw 1 pt 7 ps 1.5 pi -1
set style line 8 lc rgb "black" lt 8 lw 1 pt 8 ps 1.5 pi -1 ## triangle
set style line 1 lc rgb "#e41a1c" lt 1 lw 5 pt 1 ps 1.5 pi -1 ## +
set style line 2 lc rgb "#377eb8" lt 2 lw 5 pt 2 ps 1.5 pi -1 ## x
set style line 3 lc rgb "#4daf4a" lt 5 lw 5 pt 3 ps 1.5 pi -1 ## *
set style line 4 lc rgb "#984ea3" lt 4 lw 5 pt 4 ps 1.5 pi -1 ## box
set style line 5 lc rgb "#ff7f00" lt 3 lw 5 pt 5 ps 1.5 pi -1 ## solid box
set style line 6 lc rgb "#ffff33" lt 6 lw 5 pt 6 ps 1.5 pi -1 ## circle
set style line 7 lc rgb "#a65628" lt 7 lw 5 pt 7 ps 1.5 pi -1
set style line 8 lc rgb "#f781bf" lt 8 lw 5 pt 8 ps 1.5 pi -1 ## triangle
set style line 9 lc rgb "#999999" lt 9 lw 5 pt 9 ps 1.5 pi -1 ##
################
## data example
# Region Austria Hungary Belgium Czechoslovakia
# 1891-1900 234081 181288 18167 50231
# 1901-1910 668209 808511 41635 65285
plot data_dir.file_name.".txt" \
using 2:xtic(1) t '{/Helvetica=28 columnheader(2)}' fs pattern 2 ls 1, \
'' using 3 t '{/Helvetica=20 columnheader(3)}' fs pattern 3 ls 2, \
for [i=5:10] '' using i title '{/Helvetica=20 columnheader(i)}' fs pattern i ls i
################
## change color every bar
plot data_dir.file_name.".txt" \
u 0:($0 < 2 ? $2 : 1/0):xtic(1) with boxes ls 1 fs pattern 2, \
"" u 0:($0 < 2 ? 1/0 : $2):xtic(1) with boxes ls 2 fs pattern 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment