Fill bars in gnuplot with dots or other patterns

2019-01-20 13:01发布

问题:

I'm drawing some bar charts using gnuplot (histogram). I need different and various patterns to fill the bars. Using "fs pattern XX", I can use some patterns, but they are all some lines.

I need the border to be solid line (linetype 1), and the bar be filled by dots. If I change the linetype of pattern, then the border is changed as well. I want to keep the border solid.

Any idea?

回答1:

I found one terminal which supports dotted patterns: the lua tikz terminal:

set terminal lua tikz standalone
set output 'dot-pattern.tex'

set boxwidth 0.8 relative
set samples 10
unset key
set yrange [0:11]

plot '+' using 1:($0+1) with boxes lt -1 lw 2 lc rgb '#990000' fillstyle pattern 8
set output
system('pdflatex dot-pattern.tex')

With this you could also use custom fill patterns by overwriting a predefined pattern:

set terminal lua tikz standalone header '\tikzset{gp pattern 8/.style={pattern=mypatterh}}'

and you must define a custom pattern, like shown in Custom and built in TikZ fill patterns.

Using black borders and colored fill pattern is possible with

plot '+' using 1:($0+1) with boxes lc rgb '#990000' fillstyle pattern 8 noborder,\
     '+' using 1:($0+1) with boxes lt -1 lw 2


标签: gnuplot