【问题标题】:gnuplot text color palettegnuplot 文本调色板
【发布时间】:2013-07-22 12:09:45
【问题描述】:

我正在尝试在 gnuplot 中设置标签的 textcolor 属性以通过调色板进行过渡。
更准确地说,我希望标签的每个字母,比如"Number of Connections",都是不同的颜色,但遵循我指定的调色板。
我尝试使用以下方法,但失败了,仅使用字符串范围中间的颜色。

set palette model RGB defined ( \
0 '#F46D43',\
1 '#FDAE61',\
2 '#FEE08B',\
3 '#E6F598',\
4 '#ABDDA4',\
5 '#66C2A5' )
set y2label "Number of Connections" textcolor palette

【问题讨论】:

  • 嗨@Schorsch,我想在y 轴上有一个标签,它的颜色可以改变它的调色板,例如,其中一个gnuplot.sourceforge.net/demo/pm3dcolors.html。因此,每个字母都会有所不同,但遵循整体模式,如其中一张图所示。
  • 感谢您的澄清。这很有趣,我有一个想法,但可能需要一点时间。
  • 举个例子:类似于vps2.etotheipiplusone.com:30176/redmine/attachments/13这里的文字(虽然直截了当)。
  • Nikolay,我花了一段时间,但请看下面我的回答。

标签: gnuplot color-palette


【解决方案1】:

不幸的是,gnuplot 只能为 整个 字符串 "Number of Connections" 着色。您可以使用附加的frac option 来影响颜色。
但是,这是一种实现您想要的东西的方法。不过,它涉及一些手动设置,我将在下面解释:

# define the location of your plot:
bm = 0.15
lm = 0.12
rm = 0.75
tm = 0.90

# letter spacing - play with this as needed:
STRDIST = 0.03

# set up the plot window:
set lmargin at screen lm
set rmargin at screen rm
set bmargin at screen bm
set tmargin at screen tm

# place the colorbar in a defined location:
set colorbox vertical user origin rm+0.1,0.15 size .05,tm-bm

# define your palette:
set palette model RGB defined ( \
0 '#F46D43',\
1 '#FDAE61',\
2 '#FEE08B',\
3 '#E6F598',\
4 '#ABDDA4',\
5 '#66C2A5' )

# your label
LABEL = "Number of Connections"
# the 'length' of LABEL, unfortunately counted manually:
LEN_LABEL = 21.0 # IMPORTANT, declare as float

# use a loop to individually place each char of the string on the plot:
do for [i=1:LEN_LABEL]{\
set label i LABEL[i:i] at screen 0.8,bm+((i-1.)*STRDIST) \
    rotate by 90 textcolor palette frac i/LEN_LABEL\
}

# dummy function plot (so that there's something to see):
plot '+' using ($1):(sin($1)):(0.5*(1.0+sin($1))) w l lw 3 lc pal not

发生了什么:

  1. 定义绘图和颜色条的位置:这样您就可以准确地知道它们的位置,并且可以准确地放置“伪”标签。
  2. 变量STRDIST 用于分隔各个字母。这很笨拙,但你明白了要点。玩它以获得良好的效果。
  3. 不幸的是,gnuplot 似乎无法计算字符串的长度,所以我硬连线了它,LEN_LABEL
  4. 使用do for-loop 将标签字符串的每个字母放置在绘图上,使用附加的frac 选项从调色板中分配颜色。 frac 0.0 是调色板上的最低颜色,frac 1.0 是“最高”颜色。在这里,我们利用循环计数器从调色板中提供均匀间隔的颜色。 注意: 这就是为什么将LEN_LABEL 声明为浮点数很重要,而不是整数或任何东西,但最后一次迭代将导致frac 0
  5. plot '+' ... 命令是从this site 借用的。

复制/粘贴上述示例时得到的图如下所示:

使用“标签”的起点以及STRDIST 来生成/放置您喜欢的标签。

【讨论】:

  • 谢谢!这正是我所需要的!伟大的。你提到我的“+”解释的博文也非常有用。
猜你喜欢
  • 2019-07-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-11-15
  • 1970-01-01
相关资源
最近更新 更多