Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
675 views
in Technique[技术] by (71.8m points)

gnuplot - Fill area below a line in 3D with splot

I am plotting a 3D 'fence plot' with multiple colors for each fence. My sample data can be found here:

https://gist.github.com/anonymous/a926221ea96e92e86332

I plot this data using this:

colors = "red red red red red"
splot for [i=1:words(colors)] 'input.sep.txt' index i u 2:1:3 w lines lc rgb word(colors,i)

The lines are drawn without issue, and I believe they are drawn correctly. My question is this: how do I fill below the line so that it looks like a solid wall (i.e. all the way down to the 0 z value)? I tried using w pm3d, however this did not actually plot anything visible on the axis.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The best option you have is to use pm3d. For this to work you must change your data file a bit: You must duplicate very line, change the z-value of the duplicate to 0 and add a new line, i.e. your first two data lines

1 1 2
2 1 4

must become

1 1 2
1 1 0

2 1 4
2 1 0

and so on. You still need the two consecutive empty lines later to separate different "walls".

If you have control over your data output, you could change your output routine, or you can use a command line tool like sed

sed 's/^([0-9]* [0-9]* )(.*)$/&
1 0
/' gistfile1.txt

or awk:

awk '1; {print $1,$2,0,"
"}' gistfile1.txt

to do the conversion. Of course this can be done on-the-fly from within gnuplot. A complete, working script is then:

filename = 'gistfile1.txt'
sed = '< sed ''s/^([0-9]* [0-9]* )(.*)$/&
1 0
/'' '

set autoscale cbfix
set palette defined (0 'red', 1 'blue')
set pm3d depthorder
unset colorbox
unset key
set ticslevel 0
splot sed.filename using 1:2:3:(column(-2)) with pm3d

and the result using gnuplot 4.6.5 with your example data is:

enter image description here

Some additional notes:

  • The fourth column is used to select a different value than the z-value for the coloring.
  • column(-2) uses the block number (adjacent blocks are delimited by two empty lines) as color index.
  • Points belonging to different data blocks aren't connected.
  • With set autoscale cbfix you can better control the colors used for the planes.
  • If you know, that you have e.g. three planes which should have specific colors you could also use set palette defined (0 'red', 1 'green', 2 'blue').

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...