Julian Wergieluk
Julian Wergieluk

Reputation: 135

Plotting multiple columns using '-'

I am trying to figure out how to make the following code work without having to print the data multiple times (and separating the copies with '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

The code above generates the error message:

warning: Skipping data file with no valid points

I know, I can write the data to a file and call plot 'file' multiple times. Is there a way to avoid this? thanks!

Upvotes: 2

Views: 254

Answers (2)

Christoph
Christoph

Reputation: 48390

Since version 5.0 gnuplot supports data blocks, which allow you better handling of inline data:

$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

Upvotes: 0

mgilson
mgilson

Reputation: 309891

There's no (good) way to do this. Here's one pretty ugly hack:

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

It seems that we can make it look a little prettier by using line continuation in our string ...:

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

Upvotes: 1

Related Questions