gnuplot 轮廓线颜色:设置样式线和设置线型不起作用 [英] gnuplot contour line color: set style line and set linetype not working

查看:23
本文介绍了gnuplot 轮廓线颜色:设置样式线和设置线型不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照上一个 Stackoverflow 问题中的描述绘制数据:gnuplot 2D 极坐标图和来自 3D 数据集的热图 - 可能吗?大多数情况下,它对我来说效果很好,我只关注一些小细节.其中之一是如何控制轮廓线颜色和线宽.网上有很多关于使用 set style increment user 然后通过 set style line 1 lc rgb "blue" lw 2 等定义用户风格的帖子.理论上这应该强制 splot 使用新定义的样式绘制线条.我试过了,但没有用.此外,当我通过 gnuplot 安装进入帮助页面时,我发现我的版本(版本 4.7 patchlevel 0 last modified 2013-07-25)不推荐使用这种用法.建议使用 set linetype 代替,它会永久更改 gnuplot 当前调用的 gnuplot 线型的特征.杀死并重新启动 gnuplot 恢复默认线型特征.

I am plotting data as described in a previous Stackoverflow question: gnuplot 2D polar plot with heatmap from 3D dataset - possible? Mostly it is working well for me, and I am down to some small details. One of these is how to exert control over the contour line colors and linewidths. There are lots of posts on the web regarding using set style increment user followed by definition of user style via set style line 1 lc rgb "blue" lw 2 etc. In theory this was supposed to force splot to plot lines using the newly defined styles. I tried it and it did not work. In addition, when I went to the help pages through my gnuplot install, I discovered that this usage is deprecated with my version (Version 4.7 patchlevel 0 last modified 2013-07-25). It was recommended to use set linetype instead, which changes the characteristics of the gnuplot line style permanently for the current invocation of gnuplot. Killing and restarting gnuplot restores the default linetype characteristics.

接下来,我重新启动了 gnuplot,重新生成了绘图,而无需为等高线重新定义任何线型或类型.当我查看我的绘图时,我可以看到线条颜色以青色开头,然后是紫色,然后是蓝色(例如,线条类型 5、4、3 或 14、13、12 等).似乎线型通过可用样式向后移动.好吧,我想,我可以改变这些并忍受奇怪的行为.但是,在发出多个 set linetype 命令将所有这些线型更改为明显不同的东西后(我通过运行 test 命令验证了这些,图上的轮廓线仍然具有相同的颜色和线宽和以前一样.我似乎无法弄清楚轮廓线使用的是什么线型,所以我无法更改适当的线型.

Next, I restarted gnuplot, regenerated the plot without redefining any line style or type for the contour lines. When I looked at my plot, I could see that the line colors start with cyan, then purple, then blue (e.g. like line types 5,4,3 or 14,13,12, etc.). It seems as if the line types are going BACKWARDS through the available styles. OK, I thought, I can just change those and live with the odd behavior. However, after issuing multiple set linetype commands that changed all of these line types to something that would be obviously different (I verified these by running the test command, the contour lines on the plot still had the same color and line width as before. I can't seem to figure out what linetype is being used for the contour lines, so I can't change the appropriate linetype.

也许这种奇怪的行为是等高线类型set cntrparam levels increment -6,-6,-24 的结果,负值和/或负向增量导致了一些不可预测的行为?

Perhaps this odd behavior is a result of the contour line being of type set cntrparam levels increment -6,-6,-24 and the negative values and/or negative going increment are causing some unpredictable behavior?

我想知道如何知道此图中的等高线将使用哪种线型,以及如果用于构建曲面图的线数发生变化,轮廓线是否会发生变化.例如,下图使用 13 条线"来使用 set pm3d map 生成表面.因此,假设 N=13 条线 - 第一个轮廓线型是否遵循规则?例如,我是否总是确定等高线样式将从 N=14 开始?当输入数据中的线"数不同时,我想知道第一条和后续等高线将使用哪种线型.

I'd like to know how I can know what line type will be used for contour lines in this plot, and whether that will change if the number of lines used to build the surface plot change. For instance, the plot shown below uses 13 "lines" to generate the surface using set pm3d map. So let's say N=13 lines - is there a rule that is obeyed for the first contour linetype?. For instance, will I always be sure that the contour line style will start at N=14? I'd to know what line type will be used for the first and subsequent contour lines when the number of "lines" in my input data will vary.

最重要的是,我需要对用于每个轮廓级别的轮廓线应用某种样式.当输入数据发生变化时,我希望对每个级别始终使用相同的样式.该图将始终使用一组相同的等高线级别:-6、-12、-18 和 -24.绘图数据的最大z"坐标始终为 0 左右,然后从那里减小.

The bottom line is that I need to apply certain style to the contour lines used for each contour level. I want to consistently use the same style for each level when the input data changes. The plot will always use the same set of contour levels: -6, -12, -18, and -24. The plot data will always have a maximum "z" coordinate of about 0 and decrease from there.

Gnuplot 命令如下所示.该图的数据集可以在这里下载:http://audio.claub.net/temp/new_test.dat

Gnuplot commands are shown below. The dataset for this plot can be downloaded here: http://audio.claub.net/temp/new_test.dat

reset 
set terminal pngcairo size 800,800 
set output '3d-polar.png'

set lmargin at screen 0.05
set rmargin at screen 0.85
set bmargin at screen 0.1
set tmargin at screen 0.9

set pm3d map interpolate 20,20
unset key

set multiplot

# plot the heatmap

set cntrparam bspline
set cntrparam points 10
set cntrparam levels increment -6,-6,-24
set contour surface
#set style increment user           #NOTE: the commented out lines do not seem to affect color or width of the the contour lines no matter what number I use for the linetype
#set linetype 8 lc rgb "blue" lw 2
#set linetype 9 lc rgb "black" lw 1
#set linetype 10 lc rgb "orange" lw 1
#set linetype 11 lc rgb "yellow" lw 1

set palette rgb 33,13,10 #rainbow (blue-green-yellow-red)
set cbrange [-18:0]

unset border
unset xtics
unset ytics

set angles degree
r = 3.31 #This number is Log10(max frequency) - Log10(min frequency) of the polar frequency grid 
set xrange[-r:r]
set yrange[-r:r]
set colorbox user origin 0.9,0.1 size 0.03,0.8
splot 'new_test.dat'

# now plot the polar grid only
set style line 11 lc rgb 'black' lw 2 lt 0
set grid polar ls 11
set polar
set logscale r 10
set rrange[10:20000]
unset raxis
set rtics format '' scale 0
#set rtics axis scale 
set rtics (20,50,100,200,500,1000,2000,5000,10000,20000)
do for [i=-150:180:30] {
dum = r+0.15+0.05*int(abs(i/100))+0.05*int(abs(i/140))-0.05/abs(i+1)
set label i/30+6 at first dum*cos(i), first dum*sin(i) center sprintf('%d', i)
}
set label 20 at first 0, first -(log(20)/log(10)-1) center "20"
set label 100 at first 0, first -(log(100)/log(10)-1) center "100"
set label 200 at first 0, first -(log(200)/log(10)-1) center "200"
set label 1000 at first 0, first -(log(1000)/log(10)-1) center "1k"
set label 2000 at first 0, first -(log(2000)/log(10)-1) center "2k"
set label 10000 at first 0, first -(log(10000)/log(10)-1) center "10k"
set label 20000 at first 0, first -(log(20000)/log(10)-1) center "20k"
plot NaN w l
unset multiplot
unset output

不控制等高线的图如下所示.我需要能够为轮廓线指定线条颜色和宽度.怎么样?

The plot with no control over the contour lines is shown below. I need to be able to specify line color and width for the contour lines. How?

推荐答案

这里介绍了如何更改等高线的线属性.我无法解释为什么会这样,我只是通过测试才发现的.不幸的是,没有关于这些细节的文档.

Here is how you can change the line properties of the contour lines. I can't explain why it is that way, I just found out by testing it. Unfortunately, there is no documentation about these details.

行为如下(用 4.6.3. 和 4.7(2013-07-25 和 2013-09-09)测试,都表现出相同的行为):

The behaviour is as follows (tested with 4.6.3. and 4.7 (2013-07-25 and 2013-09-09), all show the same behaviour):

  1. 如果没有为 splot 指定 linetype,表面本身将使用 lt 1.在这种情况下,第一个轮廓是用 lt 3 绘制的.是的,与指定的增量相比,编号是倒退的.但是您可以使用 set cntrparam levels increment -6,-6,-18set cntrparam levels increment -18,6,-6

  1. If no linetype is specified for splot, the surface itself would use lt 1. In that case the first contour is drawn with lt 3. Yes, the numbering is backwards compared to the specified increment. But you can reverse it by using set cntrparam levels increment -6,-6,-18 or set cntrparam levels increment -18,6,-6

所有轮廓的linewidth 是相同的,也等于用于绘图命令的linewidth,改变它使用例如splot 'new_test.dat' lw 3.

The linewidth of all contours is the same and also equal to the linewidth used for the plotting command, to change it use e.g. splot 'new_test.dat' lw 3.

结果(没有较粗的线条)如问题所示.

The result (without the thicker lines) is as shown in the question.

  1. 轮廓使用linestyle,其索引比绘图命令使用的索引高1.

  1. The contours use the linestyle with an index by one higher than the one used by the plotting command.

您还必须定义第一个 linestyle,它将被曲面使用.如果未定义此样式,则轮廓将退回使用 linetype.

You must also define the first linestyle, which would be used by the surface. If this style is not defined, the contours fall back to using linetype.

linewidth 取自第一个 linestyle,所有 lw 设置来自以下 ls被忽略.

The linewidth is taken from the first linestyle, all lw settings from the following ls are ignored.

使用自定义线型

  1. 等高线使用linetype,其索引比绘图命令使用的索引高1.

  1. The contours use the linetype with an index by one higher than the one used by the plotting command.

所有linetype都必须自定义,也是第一个,曲面使用的.否则使用默认设置.

All linetype must be customized, also the first, the one used by the surface. Otherwise the default settings are used.

lwlinestyle 相同.

为了测试,我使用了您的数据和以下精简脚本:

For testing I used your data and the following stripped down script:

reset 
set terminal pngcairo size 800,800 
set output '3d-polar.png'

set lmargin at screen 0.05
set rmargin at screen 0.85
set bmargin at screen 0.1
set tmargin at screen 0.9

set pm3d map interpolate 20,20

# plot the heatmap
set cntrparam bspline
set cntrparam points 10
set cntrparam levels increment -6,-6,-18
set contour surface

set palette rgb 33,13,10
set cbrange [-18:0]

unset border
unset xtics
unset ytics

set angles degree
r = 3.31
set xrange[-r:r]
set yrange[-r:r]
set colorbox user origin 0.9,0.1 size 0.03,0.8

# load one of the following files:
#load 'linestyle.gp'
#load 'linetype.gp'

splot 'new_test.dat' title ' '

cbrange 仅定义为 -18,因此我相应地更改了轮廓级别(-24 无论如何都没有绘制).

The cbrange is defined only down to -18, so I changed the contour levels accordingly (-24 wasn't drawn anyway).

我使用的两个轮廓设置文件"是:

The two 'contour settings files', which I use are:

linetype.gp:

set linetype 1 lc rgb "blue" lw 3
set linetype 2 lc rgb "black"
set linetype 3 lc rgb "orange"
set linetype 4 lc rgb "yellow"

linestyle.gp:

设置样式增量用户

set style line 1 lc rgb 'blue' lw 3
set style line 2 lc rgb 'black'
set style line 3 lc rgb 'orange'
set style line 4 lc rgb 'yellow'

两者都给出相同的输出图像:

Both give the same output image:

要将它用于您的完整脚本,只需在 splot 命令之前直接加载两个文件之一.这给出了输出:

To use this for your complete script, just load one of the two files directly before the splot command. This gives the output:

在你关于轮廓的第一个问题之后,我正准备提交一个错误报告,但结果证明将其归结为具体问题相当困难.有了这个问题,它可能会更容易.我会看看我是否有时间做这件事.

After your first question about contours, I was about to submit a bug report, but it turned out to be rather difficult to boil it down to concrete questions. With this question it might be easier. I'll see if I find some time to do this.

这篇关于gnuplot 轮廓线颜色:设置样式线和设置线型不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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