问题描述
我想用彩色背景和图案填充条形图.在Gnuplot中可以吗?
I want to fill a bar with both a color background and a pattern. Is it possible in Gnuplot?
我正在使用Gnuplot 4.6.5
I am using Gnuplot 4.6.5
我现在拥有的代码:
# set terminal pngcairo transparent 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 xtics ()
set title "US immigration from Northern Europe\nPlot selected data columns as histogram of clustered boxes"
i = 22
set yrange [0:2000]
set style line 1 lc rgb 'orange';
set style line 2 lc rgb 'pink';
plot for [i=2:7] 'data.dat' using i:xtic(1) ti col ls i%2+1;
数据文件:
Region Denmark France Demark-Women France-women Demark-man France-men
1891-1900 1000 1100 500 600 500 500
1901-1910 1500 1600 1000 600 500 1000
以下是下载脚本的链接: https://dl.dropboxusercontent. com/u/45318932/histograms2.plt 和数据文件: https://dl.dropboxusercontent.com/u/45318932/data.dat
Here are the links to download the script: https://dl.dropboxusercontent.com/u/45318932/histograms2.plt and data file: https://dl.dropboxusercontent.com/u/45318932/data.dat
脚本给了我
我想要的是:
如果有人可以帮助我改进代码以产生第二个数字,将不胜感激.谢谢.
It would be much appreciated if someone can help me improve the code to produce the second figure. Thanks.
推荐答案
这很棘手,因为您不能更改填充图案的背景颜色.默认情况下,图案的背景颜色为白色,并且不是透明或为空.
That one is very tricky because you cannot change the background color of the fill patterns. And by default the background color of the patterns is white, and not transparent or empty.
唯一可以适当操作的端子是lua tikz
端子.在这里,我首先绘制所有颜色框,然后在第二次迭代中填充图案.要进行新的迭代,请使用newhistogram
选项,但这会导致图例出现空白.
The only terminal which can be manipulated adequately is the lua tikz
terminal. Here, I first draw all the color boxes, and later in a second iteration the fill patterns. To have a new iteration, I use the newhistogram
option, which however causes a gap in the legend.
要删除填充图案的白色背景,请使用sed
从输出流中删除相关部分.相当hacky,但是它可以工作:
To remove the white background of the fill patterns, I remove the relevant parts from the output stream with sed
. Quite hacky, but it works:
set terminal lua tikz standalone size 5in, 3in color
set output '| sed ''s/\\gpfill{color=gpbgfillcolor}//g'' > histograms.tex'
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 xtics ()
set title "US immigration from Northern Europe\nPlot selected data columns as histogram of clustered boxes"
i = 22
set yrange [0:2000]
set xrange [-1:2]
set style line 1 lc rgb 'orange';
set style line 2 lc rgb 'pink';
plot for [i=2:7] 'data.dat' using i:xtic(1) ti columnhead(i > 3 ? 10 : i) ls i%2+1 fillstyle solid noborder,\
newhistogram at -1, \
'' using 2 ti 'total' lt -1 fillstyle empty,\
'' using 3 notitle lt -1 fillstyle empty,\
'' using 4 title 'women' lt -1 fillstyle pattern 5,\
'' using 5 notitle lt -1 fillstyle pattern 5,\
'' using 6 title 'men' lt -1 fillstyle pattern 6,\
'' using 7 notitle lt -1 fillstyle pattern 6
set output
system('pdflatex histograms.tex')
4.6.5的结果:
刚刚发现,您可以将图案指定为不具有背景颜色,例如
Just found out, that you can specify the patterns to have no background color like
... fillstyle pattern 6 transparent
哪些终端可以使用取决于gnuplot版本:
For which terminals that works depends on the gnuplot version:
plot x with filledcurves x1 fillstyle solid fc rgb '#990000',\
x with filledcurves x1 fillstyle pattern 4 transparent lc rgb 'white'
结果(使用svg终端和4.6.5版):
Result (with svg terminal and version 4.6.5):
这篇关于Gnuplot:如何用彩色背景和图案填充条形图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!