Gnuplot:将数据集的线和点颜色与颜色条相关联

Gnuplot: Associating line and point color of a dataset to a colorbar

考虑以下最小 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 个数据集每个(每个子图中的 8 个键使情节看起来非常混乱)。因此,我希望所有 3 个子图都有一个通用的颜色条,指示每个子图中数据集的数量(1、2、3 等)。有关我的意思的示例,请参阅 this screenshot taken from this journal article

我不太清楚你说的 colorbar 是什么意思? 你是说图例还是钥匙? 在 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:(*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:(*i):(i) w lp pt 6 palette notitle

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

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

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

unset multiplot
### end of code

结果: