问题描述
这是使用Matplotlib创建的.是否可以在Gnuplot 5中进行相同类型的着色?
This was created with Matplotlib. Is it possible to make the same type of shading in Gnuplot 5?
推荐答案
我不知道gnuplot具有渐变填充选项,但是我可能错了.以下是一些丑陋"的解决方法.您基本上可以在彼此之上创建3个地块.您可能需要调整调色板以获得所需的颜色和平滑的过渡.
I'm not aware that gnuplot has a gradient fill option, but I could be wrong.The following is a bit of an "ugly" workaround. You basically create 3 plots on top of each other. You might want to adjust the palette to get the desired colors and a smooth transition.
- 用于将调色板作为背景(即颜色框与图形一样大)的虚拟绘图
- 将
y> f(x)
和y> 0
上方的部分覆盖到x2
轴以及y 和
y< 0
到x1
轴. 再次绘制
f(x)
以查看f(x)
和轴tics
a dummy plot to get the palette as background (i.e. the colorbox as large as the graph)
cover the part above
y>f(x)
andy>0
tox2
-axis as well as belowy<f(x)
andy<0
tox1
-axis.plot again
f(x)
to seef(x)
and the axes tics again
修改:该代码的早期版本使用
multiplot
.没必要,只需使用 set colorbox back
.但是随后 set xzeroaxis ls -1
不再可见,请添加 plot 0 w lls -1
.
The earlier version of the code used
multiplot
. It's not necessary, just use set colorbox back
. But then set xzeroaxis ls -1
is not visible anymore, add plot 0 w l ls -1
instead.
代码:
### filled curve with gradient
reset session
f(x) = sin(x)/(1+x)
fabove(x) = f(x)<0 ? 0 : f(x)
fbelow(x) = f(x)>0 ? 0 : f(x)
set samples 200
set palette defined (0 "white", 1 "red", 2 "black")
set colorbox back user origin graph 0, graph 0 size graph 1, graph 1
unset cbtics
set xrange[0:15]
set xzeroaxis ls -1
set yrange[-0.2:0.5]
plot fabove(x) w filledcurves x2 fc rgb "white" not, \
fbelow(x) w filledcurves x1 fc rgb "white" not, \
f(x) w l lw 2 lc rgb "black", \
NaN palette, \
0 w l ls -1
### end of code
结果:
这篇关于Gnuplot 5:曲线之间的颜色渐变底纹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!