【问题标题】:Gnuplot filledcurves flip axesGnuplot 填充曲线翻转轴
【发布时间】:2018-06-04 08:53:31
【问题描述】:

有一种样式可以填充 x 的两个函数之间的空间。 可以找到此类图的示例,例如在http://gnuplot.sourceforge.net/demo/fillbetween.html 有没有办法制作类似的情节,但翻转 x 和 y 轴? 这是所需的曲线形状(当然,没有旋转/镜像标签、标题和图例)...

它可以用闭合轮廓来完成(就像这里的最后一个例子http://www.gnuplot.info/demo_svg_cvs/fillcrvs.html),但这需要重新洗牌数据文件。还有其他选择吗?

谢谢!

【问题讨论】:

  • 从技术上讲,上图不再是 x 的函数。您实际上是在绘制函数还是从数据文件中绘制?如果您包含接近您想要的代码,它也会有所帮助。函数更难,你需要反转你的函数。数据文件会更容易。研究实际旋转 tic 标记并将“标题”放置为旋转标签。传奇更难。但是有了上面的内容,在 plot 命令中有一个空白标题(标题“”)。如果您需要图例,check this out
  • 谢谢!我尝试绘制一个数据文件。可能,使用填充曲线封闭和调整数据文件确实更容易......

标签: gnuplot


【解决方案1】:

您不能直接执行此操作。来自help filledcurves

第三个变量填充在同一组采样的两条曲线之间的区域 x 坐标。它需要三列输入数据(x、y1、y2)。

我认为您不能直接指定 (y, x1, x2)。作为一种解决方法,您可以用某种颜色在 y 轴和较大函数之间的区域,然后用白色填充 y 轴和较小函数之间的区域:

x1(y) = cos(y)+1
x2(y) = cos(y)+2
xmax(y) = (x1(y) > x2(y) ? x1(y) : x2(y))
xmin(y) = (x1(y) < x2(y) ? x1(y) : x2(y))

plot '+' using (xmax($1)):1 with filledcurve y1, \
     '+' using (xmin($1)):1 with filledcurve y1 fillcolor rgb "white"

如果两个函数中的一个或两个可能为负数,则可能需要稍作调整。

【讨论】:

  • 谢谢!不错的调整!就我而言,它更简单,因为各个行都是百分位数..
【解决方案2】:

使用 gnuplot >=5.2 可以进一步调整,因为它允许数组。 以下代码显示了如何实现垂直方向曲线之间的填充曲线的解决方法。您甚至可以使用透明度。如果您下载附加的 PNG,您会注意到它实际上具有透明背景。此解决方法背后的基本思想是制作封闭区域并填充它们。为此,您需要反转一个边框,连接边框并填充它们。不幸的是,gnuplot 没有反转列中数据点的功能,因此您必须自己在特殊过程中执行此操作。

代码:

### "Vertical" filledcurves
reset session

# create some dummy data
N = 50
set samples N
set xrange [-5:5]
set table $Data
    plot '+' u (sin($1)):1:(rand(0)*0.3+1) with table
unset table

# put Borders into arrays
stats $Data nooutput
RowCount = STATS_records
array BorderX1[RowCount]
array BorderX2[RowCount]
array BorderY[RowCount]
set table $Dummy
    plot $Data u (BorderX1[$0+1]=$1-$3):(BorderX2[$0+1]=$1+$3):(BorderY[$0+1]=$2) with table
unset table

# reverse BorderX2 and merge borders
set samples RowCount
set table $Border
    plot '+' u (BorderX1[$0+1]):(BorderY[$0+1]) with table
    plot '+' u (BorderX2[RowCount-$0]):(BorderY[RowCount-$0]) with table
unset table

# make the plot
set object 1 rect at 0,-3 size 10,0.5 fs solid 1.0 fc rgb "black" back
set yrange[-5:5]
plot \
    $Border u 1:2 w filledcurves fc rgb "#AA00FF00" not,\
    $Border u ($1*1.5):2 w filledcurves fc rgb "#AAFFFF00" not,\
    $Data u ($1+2.5):2 w filledcurves y2 fc rgb "brown" not,\
    $Data u 1:2 w l lw 8 lc rgb "blue" not,\
    '+' u 1:(cos($1)-0.5):(cos($1)+0.5) w filledcurves lc rgb "grey" not,\
    '+' u 1:(cos($1)):(1) w l lw 3 dt 2 lc rgb "white" not
### end of code

结果:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多