gnuplot:使用调色板/渐变线条颜色的绘图函数:看起来统一,而不是渐变

问题描述 投票:0回答:1

gnuplot
需要什么来绘制函数的线**使用
palette
线色,即作为渐变? (我尝试了
terminal wxt 0 enhanced
svg
,但会尝试更多)?文档说
palette
是“用于为 pm3d 表面、热图和其他绘图元素着色。”

** 答案后注意:功能类型将非常重要 - 例如

set parametric
与例如
sin(x)
完全不同 - 见下文。

A number of Stack Overflow 帖子展示了如何使用 gnuplot 从输入数据文件中绘制 data 点作为梯度,使用

palette
作为
linecolor
- 这些工作如我手中和
wxt
svg
终端(未显示 - 我会尝试其他一些)。

我尝试按照描述绘制

sin(x)

reset
unset key
set palette defined ( 0 "blue", 1 "red" )
plot sin(x) lw 3 lc palette z

我可以看到右侧的渐变条/键,从 -10 到 10(红色),但该线在刻度上似乎为零(在本例中)——既不是 -10(蓝色)也不是 10(红色) )(见图):

顺便说一句:我认为

set key off
应该避免钥匙出现在剧情中?似乎不是(这显然使用默认的
palette
):(扰流板:关闭右侧的色阶/键栏:
unset colorbox
- 请参阅下面答案后的评论。)

reset
set key off
plot sin(x) lw 3 lc palette z

我正在寻找的一个例子 - 使用一条连续改变颜色的线绘制的函数,如图所示 - 可以在this SO post about

matlab
.

中找到

总而言之:上面的

gnuplot
命令是否缺少某些功能,如
sin(x)
用梯度绘制 - 或者可能是重复梯度,所以它重新开始?

使用的程序/环境:

gnuplot 5.4 补丁级别 2

Ubuntu 22.04

function plot gnuplot gradient palette
1个回答
1
投票

如果你想使用

palette z
可变线条颜色你必须给一个 z 列,例如
plot ... (x):(y):(z)...
。如果您使用的是函数,这不会直接起作用。

但是你有特殊的文件名

+
(检查
help special-filenames
)这是相似的但是你可以在其中给出列,例如

plot '+' u 1:(sin($1)):(sin($1)) w lines palette z

代替

$1
你也可以使用
x
.

脚本:

### plot with lines with palette
reset session
unset key
set palette defined ( 0 "blue", 1 "red" )

plot '+' u 1:(sin(x)):(sin(x)) w l lw 3 lc palette z
### end of script

结果:

© www.soinside.com 2019 - 2024. All rights reserved.