使用' - '绘制多个列

问题描述 投票:2回答:2

我试图弄清楚如何使以下代码工作,而不必多次打印数据(并用'e'分隔副本):

plot '-' using 1:2, '-' using 1:3
-1 0.000679244 0.000246399
-0.99875 0.000687629 0.000251162
-0.9975 0.000696107 0.000256024
-0.99625 0.000704678 0.000260987
-0.995 0.000713343 0.000266052
-0.99375 0.000722103 0.000271221
-0.9925  0.00073096 0.000276496
-0.99125 0.000739913 0.000281879
-0.99 0.000748965 0.000287372

上面的代码生成错误消息:

warning: Skipping data file with no valid points

我知道,我可以将数据写入文件并多次调用plot 'file'。有办法避免这种情况吗?谢谢!

gnuplot
2个回答
1
投票

没有(好的)方法可以做到这一点。这是一个非常丑陋的黑客:

s = "-1 0.000679244 0.000246399\n-0.99875 0.000687629 0.000251162\n-0.9975 0.000696107 0.000256024\n-0.99625 0.000704678 0.000260987\n-0.995 0.000713343 0.000266052\n-0.99375 0.000722103 0.000271221\n-0.9925  0.00073096 0.000276496\n-0.99125 0.000739913 0.000281879\n-0.99 0.000748965 0.000287372"

plot sprintf('<echo "%s"',s) using 1:2, sprintf('<echo "%s"',s) using 1:3

似乎我们可以通过在字符串中使用行继续来使它看起来更漂亮......:

inline_file ="\
-1 0.000679244 0.000246399\n \
-0.99875 0.000687629 0.000251162\n \
-0.9975 0.000696107 0.000256024\n \
-0.99625 0.000704678 0.000260987\n \
-0.995 0.000713343 0.000266052\n \
-0.99375 0.000722103 0.000271221\n \
-0.9925  0.00073096 0.000276496\n \
-0.99125 0.000739913 0.000281879\n \
-0.99 0.000748965 0.000287372"

plot sprintf('<echo "%s"',inline_file) using 1:2, \
     sprintf('<echo "%s"',inline_file) using 1:3

0
投票

从版本5.0开始,gnuplot支持数据块,允许您更好地处理内联数据:

$data <<EOD
-1 0.000679244 0.000246399
-0.99875 0.000687629 0.000251162
-0.9975 0.000696107 0.000256024
EOD
plot $data u 1:2, '' u 1:3
© www.soinside.com 2019 - 2024. All rights reserved.