非结构化数据等高线图:每条等高线添加单个标签的实现问题
解决非结构化数据等高线每条曲线单标签问题
问题原因
你推测的结论正确:every ::1:1:1:1仅会在每个等高值对应的顶级数据块中取第一个子块的首点添加标签,但同一等高值可能对应多条独立的等高线(多个子块),因此只有第一条曲线会显示标签。此外,set cntrlabel对你的绘图方式无效——该命令仅针对原生splot with cntrlabel生效,而你是通过set table导出数据后再手动绘制等高线和标签,需要自定义标签生成逻辑。
方案1:给每条等高线添加单个标签
通过预处理等高线数据,给每个子块(单条等高线)的首点添加标记,仅在这些点显示标签:
reset session set dgrid3d 900,900 qnorm 9 # 适配高振荡数据的插值参数 set table $Contour1 splot "datos.txt" u 1:2:3 unset table set contour set view 0,0,1 set cntrparam levels incremental -0.5,0.1,1.5 set palette rgbformulae 33,13,10 set cbrange[-0.5:1.5] set colorbox vertical user origin 0.93,0.38 size .02,.585 set xrange [0:*] unset surface # 导出包含子块分隔的原始等高线数据 set table $ContourRaw splot "datos.txt" u 1:2:3 unset table # 预处理:给每个子块的第一个点添加标记(第4列设为1) set table $ContourLabels plot $ContourRaw u 1:2:3:(strcol(0) eq "" ? 0 : (prev_block==0?1:0)) \ using ($1):($2):($3):($4) \ every ::1 \ with table \ set prev_block=(strcol(0) eq "" ? 0 : 1) unset table # 绘制底图、等高线及子块首点标签 plot $Contour1 u 1:2:3 w image notitle, \ $ContourRaw u 1:2 w l notitle lc "black", \ $ContourLabels u 1:2:3($4==1 ? sprintf("{/:Bold %.1f}",$3) : "") w labels notitle font "Times-New Roman, 12"
方案2:隔条等高线添加标签
若不需要每条曲线都打标签,可按等高值间隔筛选,仅给指定间隔的等高线添加标签:
reset session set dgrid3d 900,900 qnorm 9 set table $Contour1 splot "datos.txt" u 1:2:3 unset table set contour set view 0,0,1 set cntrparam levels incremental -0.5,0.1,1.5 set palette rgbformulae 33,13,10 set cbrange[-0.5:1.5] set colorbox vertical user origin 0.93,0.38 size .02,.585 set xrange [0:*] unset surface # 导出原始等高线数据 set table $ContourRaw splot "datos.txt" u 1:2:3 unset table # 设置标签间隔:比如每隔2条等高线打一次标签 LABEL_INTERVAL = 2 current_level = -0.5 level_count = 0 # 预处理:仅给间隔等高值的子块首点添加标记 set table $ContourLabels plot $ContourRaw u 1:2:3:(strcol(0) eq "" ? (level_count=level_count+1, current_level=current_level+0.1, 0) : (level_count % LABEL_INTERVAL == 0 && prev_block==0 ? 1 : 0)) \ using ($1):($2):($3):($4) \ every ::1 \ with table \ set prev_block=(strcol(0) eq "" ? 0 : 1) unset table # 绘图 plot $Contour1 u 1:2:3 w image notitle, \ $ContourRaw u 1:2 w l notitle lc "black", \ $ContourLabels u 1:2:3($4==1 ? sprintf("{/:Bold %.1f}",$3) : "") w labels notitle font "Times-New Roman, 12"
内容的提问来源于stack exchange,提问作者ifffam
相关产品推荐
相关产品推荐

