Gnuplot : How to fill space between dataset and graph

て烟熏妆下的殇ゞ 提交于 2020-01-15 03:26:06

问题


I have a data file with X,Y scattered data and I want to fill somehow (pattern, solid transparent, whatever) the space outside of those points.

I tried with filledcurves closed but it fills the inside, not the outside

Is there a way to fill the space without separating the data points into several lines and set fill above/below the axis?

Thank you


回答1:


Would it be an option to post process the plots with Imagemagick? Then you could produce two images, one with transparency, and combine them later like this:

# Generate some example data.
set table "heatmap.dat"
set isosamples 1000,100
splot x
unset table

set table "ellipse.dat"
set parametric
plot 8*sin(t),5*cos(t)
unset parametric
unset table

# Set this explicitly to let the borders of the two plots match exactly.
set lmargin at screen 0.1
set rmargin at screen 0.85
set bmargin at screen 0.1
set tmargin at screen 0.9
set xrange [-10:10]
set yrange [-10:10]

# We are going to produce a png file
set terminal pngcairo

# First plot of the heatmap, this will be the background.
set output "a.png"
plot "heatmap.dat" with image


# Plot again, we need the dummy heatmap for the color key.
# We use the rectangle object for filling the area outside the ellipse. (Thanks @ewcz)
# Later we interprete the color 444444 as transparent.
set output "b.png"
set object rectangle from -10,-10 to 10,10 fc rgb "#f0ddaa" fillstyle solid 1.0
plot "heatmap.dat" using 1:2:(NaN) with image notitle,\
     "ellipse.dat" using 1:2 with filledcurves lc rgb "#444444" notitle


# Overlay the pictures using imagemagick. The result is "result.png".
system('convert b.png -transparent "#444444" c.png')
system('composite -compose atop c.png a.png result.png')

This is the result:




回答2:


To achieve something like this you could first create a rectangle representing the desired background and then plot your data on top of it with white color:

set xr [-2:2]
set yr [-2:2]
set object rectangle from -2,-2 to 2,2 fc rgb "red" fillstyle solid 1.0
plot 'test.dat' w filledcurves lc rgb "white"


来源:https://stackoverflow.com/questions/42829076/gnuplot-how-to-fill-space-between-dataset-and-graph

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!