Fill area below a line in 3D with splot

2019-01-20 04:12发布

问题:

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.

回答1:

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]* \)\(.*\)$/&\n\1 0\n/' gistfile1.txt

or awk:

awk '1; {print $1,$2,0,"\n"}' 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]* \)\(.*\)$/&\n\1 0\n/'' '

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:

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').


回答2:

This is a workaround rather than a proper solution, but it might work for you. Play with the filledcurves option which is not really designed for 3D plotting. What you have, as it is, would look like:

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

Using a tricksy trick with the set dgrid3d command, you can increase the number of vertical lines that get drawn (set dgrid3d 100,2 in this case):

Until you're happy with the result (set dgrid3d 200,2):



标签: gnuplot