arrays - 如何在 gnuplot 中使用带有“with”表示法的动态变量名称?
问题描述
我想在带有for循环的plot命令中使用变量或数组,如下所示
style[1]= "lines lt 4 lw 2"
style[2] = "points lt 3 pt 5 ps 2"
....
title[1]= "first title"
title[2]= "second title "
...
或者
style="'lines lt 4 lw 2' 'points lt 3 pt 5 ps 2'"
title="'first title' 'second title'"
绘图命令
plot for [i=1:1000] 'data.txt' u 1:2 title title[i] with style[i]
plot for [i=1:1000] 'data.txt' u 1:2 title word(title,i) with word(style,i)
我在标题部分成功了,但在with部分没有成功。我意识到问题是由引号引起的。
i=1
plot 'data.txt' u 1:2 title "first title" with "lines lt 4 lw 2"
当我使用数组和单词属性时,由于引用错误而出现错误。我尝试了sprintf但仍然没有成功。
sprintf("with %s", style'.i.')
我希望我能正确解释。知道我如何解决这个问题吗?或者我怎样才能删除引号。非常感谢。
解决方案
如果您要从中选择的样式仅包含线和/或点,那么您可以通过定义相应的样式linestyle
然后按数字选择它来完成此操作。
set style line 1 lt 4 lw 2 pt 0 # lines only, no points
set style line 2 lt 3 lw 0.001 pt 5 ps 2 # points only, no lines
array Title[2] = ["style 1", "style 2"]
plot for [i=1:2] sin(x/i) with linespoints ls i title Title[i]
注意:通过将 lw 设置为 0 来抑制线条可能不起作用,因为许多终端将其解释为“最细的可能线条”而不是“无线条”。因此,我们将其设置为非常薄的东西,希望不会被看到。
如果您要从中选择的样式包括线+点以外的其他内容,那么不,我认为不可能使用此技巧。
推荐阅读
- python - 接口类型的内存视图与 python slice 对象
- amazon-web-services - 为联合身份 AWS 创建长期凭证
- javascript - JS 正则表达式字符串不会以句点/点结尾
- python - Python对象相等比较
- java - 从数据库中提取值进行操作并将它们保存在另一个表中 android
- r - 如何使用逆 CDF 方法从逻辑 CDF 生成样本
- jpa - JPA 问题:持久化具有 EmbeddedId 复合键的关联类时遇到问题
- javascript - 为什么一段代码会覆盖另一段代码?
- python - Sqlite中的变量使用python
- git - 强制 Git 总是覆盖某些文件