Gnuplot 版本 5.4 补丁级别 1:绘制多个具有单个标题的数据集(图例条目)
Gnuplot Version 5.4 patchlevel 1: plot several datasets with single title (legend entry)
我想绘制多条线。但是我希望它们都具有相同的样式并在图例中创建一个条目。
当我使用
splot '-' with lines
有了这些数据
0.0 0.0 0.0
0.1 0.1 0.1
0.0 0.1 0.0
0.2 0.2 0.2
0.3 0.3 0.3
0.3 0.2 0.3
e
一切都如我所料。同样如预期的那样,任何样式都应用于所有行。
但是如果我尝试添加标题
splot '-' with lines title "myTitle"
在图例中为每个条目生成一个条目。
我怎样才能有一个图例条目?
[注意我需要在数据集之间换行,因为我想要不同的行而不是网格]
[我正在使用 Gnuplot 版本 5.4 补丁级别 1]
谢谢!
好的,我使用 gnuplot 5.2.6 进行了测试,您看不到这种行为。漂亮,奇怪。我不确定为什么会这样。
使用 gnuplot 5.4,您可以解决以下问题。检查 help keyentry
.
代码:
### only one key for a dataset separated by two empty lines
reset session
$Data <<EOD
0.0 0.0 0.0
0.1 0.1 0.1
0.0 0.1 0.0
0.2 0.2 0.2
0.3 0.3 0.3
0.3 0.2 0.3
EOD
splot $Data w l ls 1 notitle, \
keyentry w l ls 1 title "only one title"
### end of code
编辑:(没有 keyentry
并重复线型的替代解决方案)
myTitle(i) = i==0 ? "only one title" : ""
splot for [i=0:*] $Data index i w l ls 1 title myTitle(i)
结果:
在这种情况下创建重复的键条目是有意更改的意外结果。参见 Issue #2380 duplicate titles in key。对于此处 plot 命令通过提供带引号的字符串请求标题的特定情况,旧行为将在 5.4.2 版中恢复 - 即使绘制了多个数据集,您也只会在密钥中获得一个条目。
仅供参考 - 引入更改是因为现在可以为文件中的每个数据集生成不同的标题。然而,拥有多个完全相同的标题并不是特别有用。
说明了预期用途
plot 'file.dat' using 1:2 title sprintf("Data set %d", column(-2))
其中 column(-2)
returns 此数据集的索引号。在早期的 gnuplot 版本中,您必须显式地遍历索引号
plot for [index=1:*] 'file.dat' using 1:2 title sprintf("Data set %d",index)
在版本 5.4.2 中更新显示结果
### only one key for a dataset separated by two empty lines
reset session
$Data <<EOD
0.0 0.0 0.0
0.1 0.1 0.1
0.0 0.1 0.0
0.2 0.2 0.2
0.3 0.3 0.3
0.3 0.2 0.3
EOD
set title sprintf("Gnuplot version %.1f.%s", GPVAL_VERSION, GPVAL_PATCHLEVEL)
splot $Data with lines title "myTitle"
### end of code
我想绘制多条线。但是我希望它们都具有相同的样式并在图例中创建一个条目。
当我使用
splot '-' with lines
有了这些数据
0.0 0.0 0.0
0.1 0.1 0.1
0.0 0.1 0.0
0.2 0.2 0.2
0.3 0.3 0.3
0.3 0.2 0.3
e
一切都如我所料。同样如预期的那样,任何样式都应用于所有行。
但是如果我尝试添加标题
splot '-' with lines title "myTitle"
在图例中为每个条目生成一个条目。
我怎样才能有一个图例条目?
[注意我需要在数据集之间换行,因为我想要不同的行而不是网格] [我正在使用 Gnuplot 版本 5.4 补丁级别 1]
谢谢!
好的,我使用 gnuplot 5.2.6 进行了测试,您看不到这种行为。漂亮,奇怪。我不确定为什么会这样。
使用 gnuplot 5.4,您可以解决以下问题。检查 help keyentry
.
代码:
### only one key for a dataset separated by two empty lines
reset session
$Data <<EOD
0.0 0.0 0.0
0.1 0.1 0.1
0.0 0.1 0.0
0.2 0.2 0.2
0.3 0.3 0.3
0.3 0.2 0.3
EOD
splot $Data w l ls 1 notitle, \
keyentry w l ls 1 title "only one title"
### end of code
编辑:(没有 keyentry
并重复线型的替代解决方案)
myTitle(i) = i==0 ? "only one title" : ""
splot for [i=0:*] $Data index i w l ls 1 title myTitle(i)
结果:
在这种情况下创建重复的键条目是有意更改的意外结果。参见 Issue #2380 duplicate titles in key。对于此处 plot 命令通过提供带引号的字符串请求标题的特定情况,旧行为将在 5.4.2 版中恢复 - 即使绘制了多个数据集,您也只会在密钥中获得一个条目。
仅供参考 - 引入更改是因为现在可以为文件中的每个数据集生成不同的标题。然而,拥有多个完全相同的标题并不是特别有用。
说明了预期用途plot 'file.dat' using 1:2 title sprintf("Data set %d", column(-2))
其中 column(-2)
returns 此数据集的索引号。在早期的 gnuplot 版本中,您必须显式地遍历索引号
plot for [index=1:*] 'file.dat' using 1:2 title sprintf("Data set %d",index)
在版本 5.4.2 中更新显示结果
### only one key for a dataset separated by two empty lines
reset session
$Data <<EOD
0.0 0.0 0.0
0.1 0.1 0.1
0.0 0.1 0.0
0.2 0.2 0.2
0.3 0.3 0.3
0.3 0.2 0.3
EOD
set title sprintf("Gnuplot version %.1f.%s", GPVAL_VERSION, GPVAL_PATCHLEVEL)
splot $Data with lines title "myTitle"
### end of code