gpt4 book ai didi

colors - 自定义图例(或文本)gnuplot

转载 作者:行者123 更新时间:2023-12-04 14:45:48 24 4
gpt4 key购买 nike

我有一个包含 3 列的文件,前 2 个是位置 x y 和第三个我用它来定义颜色,所以我有这样的东西:

set palette model RGB defined ( 1 'black', 2 'blue', 3 'green', 4 'red')
unset colorbox

plot "file" u 2:1:3 w points pt 14 ps 2 palette, "file2" u 2:1:3 w points pt 14 ps 2 palette

现在的问题是:这种点和颜色是否有可能有一个合适的图例?。
由于点将具有不同的颜色(根据调色板),我想指定图例中每种颜色的含义。

我想的唯一解决方案是在情节的某个地方写一些带有点特征的文本(在本例中为 pt 14)并指定颜色……但这不是真正的解决方案吗?

所以请帮忙!

最佳答案

对此没有选择,您需要稍微摆弄一下。这是 YAGH(又一个 gnuplot hack);)

假设您的值等距间隔,您可以使用 '+'带有 labels 的特殊文件名绘图风格。

要仅显示自定义键,请考虑以下示例:

labels="first second third fourth"
set xrange[0:1] # must be set for '+'
set yrange[0:1]
set samples words(labels) # number of colors to use
key_x = 0.8 # x-value of the points, must be given in units of the x-axis
key_y = 0.8
key_dy = 0.05
set palette model RGB defined ( 1 'black', 2 'blue', 3 'green', 4 'red')
unset colorbox
plot '+' using (key_x):(key_y + $0*key_dy):(word(labels, int($0+1))):0 \
with labels left offset 1,-0.1 point pt 7 palette t ''

这给出(4.6.4):

enter image description here

set samples不会影响数据图,您可以将其直接集成到您的绘图命令中:
...
unset key
plot "file" u 2:1:3 w points pt 14 ps 2 palette, \
"file2" u 2:1:3 w points pt 14 ps 2 palette, \
'+' using (key_x):(key_y - $0*key_dy):(word(labels, int($0+1))):0 \
with labels left offset 1,-0.1 point pt 14 ps 2 palette

但是你需要设置一个合适的xrange、yrange和 key_x的值。 , key_ykey_dy .

这不是最直观的方式,但它有效:)

关于colors - 自定义图例(或文本)gnuplot,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20245287/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com