gnuplot:如何只有一个轮廓标签(间隔 -1 不工作)

gnuplot : how to have only one label of contour (interval -1 does ont work)

我正在尝试 'contour map' 2 个变量的函数。 我的问题是我希望标签沿着轮廓集只显示一次(最好是在轮廓长度的中间)。我尝试了 set cntrparam start n interval m 的任意组合 (包括<0)但我没能做到(有时没有标签有时太多,但从来没有只有一个)。 我需要足够高的样本以获得 "smooth" 数字...

如有任何帮助,我们将不胜感激, 问候,

这是我的代码:

set isosamples 200,200
set cntrlabel  format start 50 interval -1 font '.7' onecolor
set cntrparam levels discrete 
-50,-400,-300,-200,-100,50,20,100,200,300,400,500,0,-20
set xrange [-5:5]
set yrange [-5:5]
set title "Ensembles de niveaux "
set xlabel " X "
set ylabel "Y "
set contour base
set view map

splot 4*x**3+4*y**3 with lines  lw 3, 4*x**3+4*y**3 with labels point  pointinterval -1

以及预期输出:

来自 gnuplot help ctrlabel:

Setting the interval to a negative value means that the label appear only once per contour line. However if set samples or set isosamples is large then many contour lines may be created, each with a single label.

我想这在 gnuplot 5.4 中没有改变。 这意味着如果您减少 isosamples 的数量,您可能会在每条等高线上获得所需的单个标签, 但是,缺点是曲线精度较低。可能,当 gnuplot 开始将等高线分成几条子线时(尽管一条线就足够了),可能不容易“预测”。

老实说,我还不知道有什么简单而令人满意的解决方法。

代码:(稍作修改)

### contour lines with only one label per line
reset session

set cntrlabel format start 50 interval -1 onecolor
set cntrparam levels discrete -400,-300,-200,-100,-50,-20,0,20,50,100,200,300,400,500
set xrange [-5:5]
set yrange [-5:5]

set contour base
set view map
unset surface
set key noautotitle

f(x,y) = 4*x**3+4*y**3

set multiplot layout 2,1

    set title "isosamples 25,25"
    set isosamples 25,25 
    splot f(x,y) w l, \
          f(x,y) w labels point pi -1

    set title "isosamples 200,200"
    set isosamples 200,200 
    splot f(x,y) w l, \
          f(x,y) w labels point pi -1
          
unset multiplot
### end of code

结果:

添加:(获得高精度轮廓的解决方法 仅限单个标签)

这个简单但奇怪的解决方法的想法是将等高线两次绘制到两个表中。 一次是轮廓线的高精度,一次是标签的低精度(这已经足够好了)。 而不是 splot 数据绘制为 plot.

代码:

### contour lines with only one label per line
reset session

set cntrlabel format start 50 interval -1 onecolor
set cntrparam levels discrete -400,-300,-200,-100,-50,-20,0,50,20,100,200,300,400,500
set xrange [-5:5]
set yrange [-5:5]

set contour base
set view map
unset surface
set key noautotitle

f(x,y) = 4*x**3+4*y**3

set isosamples 25,25 
set table $ContourLabels
    splot f(x,y)
unset table

set isosamples 200,200 
set table $Contour
    splot f(x,y)
unset table

plot $Contour u 1:2 w l lc "web-green", \
     $ContourLabels u 1:2:3 every ::50::50 w labels
### end of code

结果: