【问题标题】:Gnuplot: Associating line and point color of a dataset to a colorbarGnuplot:将数据集的线和点颜色与颜色条相关联
【发布时间】:2020-07-21 09:14:03
【问题描述】:

考虑以下最小的 gnuplot 脚本:

set terminal epslatex size 4.1,3
set out 'Plot.tex'

plot './Plot1.out' u 1:3 notitle w linespoints lt 1 pt 6 ps 1 lc rgb 'black', \
     './Plot2.out' u 1:3 notitle w linespoints lt 1 pt 6 ps 1 lc rgb 'red', \
     './Plot3.out' u 1:3 notitle w linespoints lt 1 pt 6 ps 1 lc rgb 'blue', \
     './Plot4.out' u 1:3 notitle w linespoints lt 1 pt 6 ps 1 lc rgb 'green'

set out

我目前分别为图 1、2、3 和 4 用黑色、红色、蓝色和绿色绘制每个图。如何添加与范围 [1,4] 关联的颜色条,并使每个绘图的颜色对应于其关联的绘图编号(1、2、3 或 4)?

编辑:我特别不想为此使用密钥,因为在我的实际示例中,我有 3 个并排堆叠的子图,每个子图有 8 个数据集(在每个子情节都使情节看起来非常混乱)。因此,我希望有一个对所有 3 个子图通用的颜色条,指示每个子图中数据集的数量(1、2、3 等)。有关我的意思的示例,请参阅取自 this journal articlethis screenshot

【问题讨论】:

  • 抱歉,无法访问链接...
  • 我一会儿上传截图。

标签: plot gnuplot colorbar


【解决方案1】:

我不太清楚你所说的颜色条是什么意思? 你是说传说还是钥匙? 在 plot 命令中使用 notitle 可以避免使用键或图例。

检查以下最小示例:

代码:

### plots in a loop with key
reset session

set style line 1 pt 6 ps 1 lc rgb "black"
set style line 2 pt 6 ps 1 lc rgb "red"
set style line 3 pt 6 ps 1 lc rgb "blue"
set style line 4 pt 6 ps 1 lc rgb "green"

set key top center

plot for [i=1:4] '+' u 1:($1*i) w lp ls i title sprintf("%d",i)

### end of code

结果:

为您的特定文件添加一个定义文件名的函数并相应地交换绘图命令。

myFile(i) = sprintf("./Plot%d.out",i)

plot for [i=1:4] myFile(i) u 1:3 w lp ls i title sprintf("%d",i)

加法:

那么也许是这样的?这只是说明原理。以相同的图形大小和彼此之间的距离以及颜色框以一种很好的方式排列多图是另一个主题。

代码:

### plots in a loop without key but colorbox
reset session

set style line 1 pt 6 ps 1
set style line 2 pt 6 ps 1
set style line 3 pt 6 ps 1
set style line 4 pt 6 ps 1

set palette defined (1 "black", 2 "red", 3 "blue", 4 "green")

set multiplot layout 2,2

    set cbtics 1
    set key out top right
    unset colorbox
    plot for [i=1:4] '+' u 1:($1*i):(i) w lp pt 6 palette notitle

    unset ytics
    set colorbox
    plot for [i=1:4] '+' u 1:($1*i):(i) w lp pt 6 palette notitle

    unset colorbox
    set ytics
    plot for [i=1:4] '+' u 1:($1*i):(i) w lp pt 6 palette notitle

    unset ytics
    set colorbox
    set palette maxcolors 4
    plot for [i=1:4] '+' u 1:($1*i):(i) w lp pt 6 palette notitle

unset multiplot
### end of code

结果:

【讨论】:

  • 感谢您的回答。我特别输入了“notitle”,因为我不想包含密钥。这是因为在我的实际情节中,有 8 个情节。而且我想使用 multiplot 有 3 个单独的子图,它们具有相同的 y 轴并排堆叠。所以我想在多图的右侧添加一个垂直条,指定颜色(颜色条),这样我就不必在每个子图中设置一个键。我希望我已经澄清了一些事情? (我怀疑正确的 gnuplot 术语是颜色图,但我不太确定)
  • 非常感谢!添加到您的原始答案正是我正在寻找的:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-10-01
  • 2021-07-12
  • 2015-04-20
  • 2021-06-13
相关资源
最近更新 更多