Gnuplot 5:曲线之间的颜色渐变底纹 [英] Gnuplot 5: color gradient shading between curves

查看:86
本文介绍了Gnuplot 5:曲线之间的颜色渐变底纹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是使用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.

  1. 用于将调色板作为背景(即颜色框与图形一样大)的虚拟绘图
  2. y> f(x) y> 0 上方的部分覆盖到 x2 轴以及 y <; f(x) y< 0 x1 轴.
  3. 再次绘制 f(x)以查看 f(x)和轴tics
  1. a dummy plot to get the palette as background (i.e. the colorbox as large as the graph)
  2. cover the part above y>f(x) and y>0 to x2-axis as well as below y<f(x) and y<0 to x1-axis.
  3. plot again f(x) to see f(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:曲线之间的颜色渐变底纹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆