GNUPlot:无法绘制指定颜色的二维散点图
GNUPlot: cannot plot 2D scatterplot with colors specified
我正在尝试使用收到的建议制作二维散点图
这让我写下:
$DATA << EOD
3.12960004005165 2.67469663590573 0.438527882947657
3.54159282682062 1.48608712150729 3.45059090334765
1.41832139944261 1.09739773669576 4.7851179962913
0.37050714994141 4.51679511956513 2.99273024822522
1.33417336450785 2.60931115605578 3.49852244355505
4.68608825227413 4.50263530942483 0.708639941290272
EOD
set datafile separator "\t"
set xlabel 'x'
set ylabel 'y'
set title 'title'
set terminal svg
set output 'scatterplotx_y.svg'
set key off
myColor(col) = int("0x".strcol(col)[3:])
plot $DATA using 1:2:(myColor(3)) pt 7
我正在使用 gnuplot 5.2 补丁级别 8
我也试过了
plot $DATA u 1:2:3 with lines palette
由 Line plot in GnuPlot where line color is a third column in my data file? 建议,但这不起作用
plot $DATA u 1:2:3 with points color
我现在正在使用调色板:
set palette defined (0 "red", 0.3 "orange", 0.625 "green", 0.85 "blue", 1 "dark-violet")
我的问题:
如何绘制由 [0,1] 中的数字确定的从红色到紫色的颜色,这里是第 3 列?其中红色是 0,1 是紫色,中间是彩虹的所有颜色?
颜色渐变在 GNUPlot
中称为 palette
set palette defined (0 "red", 0.3 "orange", 0.625 "green", 0.85 "blue", 1 "dark-violet")
$DATA << EOD
4.47576802144342 3.96170057191894 0.965077628065902
0.476983571877412 3.8599136240968 4.12799054681166
4.87640196476667 4.52001611814199 3.14028639266551
2.261549757545 2.24147530185633 2.92342461107236
0.0119463593595448 3.63583286650188 1.78255268707661
3.4088757971039 2.11565314670896 1.62679271015364
EOD
set datafile separator "\t"
set xlabel 'x'
set ylabel 'y'
set title 'title'
set terminal svg
set output 'scatterplotx_y.svg'
set key off
plot $DATA u 1:2:3 with points palette
我不知道为什么,但是 plot $DATA u 1:2:3 with points palette
不知何故知道第三个数据点是颜色。
您在 plot 命令中缺少一个关键字来告诉程序第三列的用途。
plot $DATA u 1:2:3 with lines linecolor palette
否则程序会忽略额外的列,因为它不知道它是 z 坐标、点大小还是其他各种可能性。
实际上 linecolor palette
选项中还有更多选择。它可以是 linecolor palette z
或 linecolor palette fraction
或 linecolor palette cb
.
- 默认第一个
palette z
。它会自动调整值以使用该图中数据的整个调色板范围。
palette fraction
表示第 3 列是一个介于 0 和 1 之间的数字,用于选择调色板范围内的颜色。
palette cb
表示第 3 列中的值是指由 set cbrange [min:max]
. 控制的单独颜色范围
我正在尝试使用收到的建议制作二维散点图
这让我写下:
$DATA << EOD
3.12960004005165 2.67469663590573 0.438527882947657
3.54159282682062 1.48608712150729 3.45059090334765
1.41832139944261 1.09739773669576 4.7851179962913
0.37050714994141 4.51679511956513 2.99273024822522
1.33417336450785 2.60931115605578 3.49852244355505
4.68608825227413 4.50263530942483 0.708639941290272
EOD
set datafile separator "\t"
set xlabel 'x'
set ylabel 'y'
set title 'title'
set terminal svg
set output 'scatterplotx_y.svg'
set key off
myColor(col) = int("0x".strcol(col)[3:])
plot $DATA using 1:2:(myColor(3)) pt 7
我正在使用 gnuplot 5.2 补丁级别 8
我也试过了
plot $DATA u 1:2:3 with lines palette
由 Line plot in GnuPlot where line color is a third column in my data file? 建议,但这不起作用
plot $DATA u 1:2:3 with points color
我现在正在使用调色板:
set palette defined (0 "red", 0.3 "orange", 0.625 "green", 0.85 "blue", 1 "dark-violet")
我的问题:
如何绘制由 [0,1] 中的数字确定的从红色到紫色的颜色,这里是第 3 列?其中红色是 0,1 是紫色,中间是彩虹的所有颜色?
颜色渐变在 GNUPlot
中称为palette
set palette defined (0 "red", 0.3 "orange", 0.625 "green", 0.85 "blue", 1 "dark-violet")
$DATA << EOD
4.47576802144342 3.96170057191894 0.965077628065902
0.476983571877412 3.8599136240968 4.12799054681166
4.87640196476667 4.52001611814199 3.14028639266551
2.261549757545 2.24147530185633 2.92342461107236
0.0119463593595448 3.63583286650188 1.78255268707661
3.4088757971039 2.11565314670896 1.62679271015364
EOD
set datafile separator "\t"
set xlabel 'x'
set ylabel 'y'
set title 'title'
set terminal svg
set output 'scatterplotx_y.svg'
set key off
plot $DATA u 1:2:3 with points palette
我不知道为什么,但是 plot $DATA u 1:2:3 with points palette
不知何故知道第三个数据点是颜色。
您在 plot 命令中缺少一个关键字来告诉程序第三列的用途。
plot $DATA u 1:2:3 with lines linecolor palette
否则程序会忽略额外的列,因为它不知道它是 z 坐标、点大小还是其他各种可能性。
实际上 linecolor palette
选项中还有更多选择。它可以是 linecolor palette z
或 linecolor palette fraction
或 linecolor palette cb
.
- 默认第一个
palette z
。它会自动调整值以使用该图中数据的整个调色板范围。 palette fraction
表示第 3 列是一个介于 0 和 1 之间的数字,用于选择调色板范围内的颜色。palette cb
表示第 3 列中的值是指由set cbrange [min:max]
. 控制的单独颜色范围