|
From: Thor A. <ta...@to...> - 2013-01-16 09:53:08
|
Hi,
I was under the impression that it is possible to plot only parts of a data
file with the ternary operator (?:), strcol() and missing ('?'), but I get
strange results.
My data file contains:
8<------8<------8<------8<------
cat << EOF > data
1 2 A
2 3 A
1 1 B
2 4 B
3 2 A
4 3 A
EOF
8<------8<------8<------8<------
Now if try to plot the lines with 'B' in the third column:
echo "set table; plot 'data' u 1:((strcol(3) eq 'B')? \$2 : '?')" | gnuplot
The result is:
8<------8<------8<------8<------
# Curve 0 of 1, 6 points
# Curve title: "'data' u 1:((strcol(3) eq 'B')? $2 : '?')"
# x y type
1 1.89869e-267 i
2 1.89869e-267 i
1 1 i
2 4 i
3 4 i
4 4 i
8<------8<------8<------8<------
Which is not what I expected. Am I doing it wrong or is this a bug?
The above was tested with a recent cvs version of Gnuplot.
gnuplot> show version long
G N U P L O T
Version 4.7 patchlevel 0 last modified 2013-01-08
Build System: Linux i686
Copyright (C) 1986-1993, 1998, 2004, 2007-2012
Thomas Williams, Colin Kelley and many others
gnuplot home: http://www.gnuplot.info
mailing list: gnu...@li...
faq, bugs, etc: type "help FAQ"
immediate help: type "help" (plot window: hit 'h')
Compile options:
-READLINE +LIBREADLINE +HISTORY
-BACKWARDS_COMPATIBILITY +BINARY_DATA
+GD_PNG +GD_JPEG +GD_TTF +GD_GIF +ANIMATION
-USE_CWDRC +X11 +X11_POLYGON +MULTIBYTE +X11_EXTERNAL +USE_MOUSE +HIDDEN3D_QUADTREE
+DATASTRINGS +HISTOGRAMS +OBJECTS +STRINGVARS +MACROS +IMAGE +USER_LINETYPES +STATS
GNUPLOT_DRIVER_DIR = "/opt/stow/gnuplot/libexec/gnuplot/4.7"
GNUPLOT_PS_DIR = "/opt/stow/gnuplot/share/gnuplot/4.7/PostScript"
HELPFILE = "/opt/stow/gnuplot/share/gnuplot/4.7/gnuplot.gih"
--
best regards
Thor Andreassen
|
|
From: Mikhail K. <mko...@gm...> - 2013-01-16 10:50:40
|
Hi Thor
why not using 1/0 specification instead of '?':
echo "set table; plot 'data' u 1:((strcol(3) eq 'B')? \$2 : 1/0)" | gnuplot
# Curve 0 of 1, 5 points
# Curve title: "'data' u 1:((strcol(3) eq 'B')? $2 : 1/0)"
# x y type
0 0 u
0 0 u
1 1 i
2 4 i
0 0 u
Mikhail
On 16/01/2013 10:53, Thor Andreassen wrote:
> Hi,
>
> I was under the impression that it is possible to plot only parts of a data
> file with the ternary operator (?:), strcol() and missing ('?'), but I get
> strange results.
>
> My data file contains:
>
> 8<------8<------8<------8<------
> cat<< EOF> data
> 1 2 A
> 2 3 A
> 1 1 B
> 2 4 B
> 3 2 A
> 4 3 A
> EOF
> 8<------8<------8<------8<------
>
> Now if try to plot the lines with 'B' in the third column:
>
> echo "set table; plot 'data' u 1:((strcol(3) eq 'B')? \$2 : '?')" | gnuplot
>
> The result is:
>
> 8<------8<------8<------8<------
> # Curve 0 of 1, 6 points
> # Curve title: "'data' u 1:((strcol(3) eq 'B')? $2 : '?')"
> # x y type
> 1 1.89869e-267 i
> 2 1.89869e-267 i
> 1 1 i
> 2 4 i
> 3 4 i
> 4 4 i
> 8<------8<------8<------8<------
>
> Which is not what I expected. Am I doing it wrong or is this a bug?
>
> The above was tested with a recent cvs version of Gnuplot.
>
> gnuplot> show version long
>
> G N U P L O T
> Version 4.7 patchlevel 0 last modified 2013-01-08
> Build System: Linux i686
>
> Copyright (C) 1986-1993, 1998, 2004, 2007-2012
> Thomas Williams, Colin Kelley and many others
>
> gnuplot home: http://www.gnuplot.info
> mailing list: gnu...@li...
> faq, bugs, etc: type "help FAQ"
> immediate help: type "help" (plot window: hit 'h')
> Compile options:
> -READLINE +LIBREADLINE +HISTORY
> -BACKWARDS_COMPATIBILITY +BINARY_DATA
> +GD_PNG +GD_JPEG +GD_TTF +GD_GIF +ANIMATION
> -USE_CWDRC +X11 +X11_POLYGON +MULTIBYTE +X11_EXTERNAL +USE_MOUSE +HIDDEN3D_QUADTREE
> +DATASTRINGS +HISTOGRAMS +OBJECTS +STRINGVARS +MACROS +IMAGE +USER_LINETYPES +STATS
>
> GNUPLOT_DRIVER_DIR = "/opt/stow/gnuplot/libexec/gnuplot/4.7"
> GNUPLOT_PS_DIR = "/opt/stow/gnuplot/share/gnuplot/4.7/PostScript"
> HELPFILE = "/opt/stow/gnuplot/share/gnuplot/4.7/gnuplot.gih"
>
--
Mikhail Kononets
Ph.D. Student
Marine Chemistry
Department of Chemistry and Molecular Biology
University of Gothenburg
Kemivagen 10
SE-412 96
Gothenburg, Sweden
office num.: +46-31-786-9063
mobile num.: +46-70-216-0936
e-mail: m.k...@ch...
mko...@gm...
|
|
From: Thor A. <ta...@to...> - 2013-01-16 11:16:26
|
On Wed, Jan 16, 2013 at 11:50:20AM +0100, Mikhail Kononets wrote: > Hi Thor Hi Mikhail, thanks for the help. > why not using 1/0 specification instead of '?': > > echo "set table; plot 'data' u 1:((strcol(3) eq 'B')? \$2 : 1/0)" | gnuplot > > # Curve 0 of 1, 5 points > # Curve title: "'data' u 1:((strcol(3) eq 'B')? $2 : 1/0)" > # x y type > 0 0 u > 0 0 u > 1 1 i > 2 4 i > 0 0 u I see, it does work better with NaNs, returning undefined for non-matching lines. The only issue is if I want to connect data points separated by one of the undefined lines, see for example: echo "plot 'data' u 1:((strcol(3) eq 'A')? \$2 : 1/0)" | gnuplot [...] -- best regards Thor Andreassen |
|
From: Mikhail K. <mko...@gm...> - 2013-01-16 11:39:52
|
you could use external data processing in this case, like:
echo "plot \"< awk '{ if (\$3==\\\"A\\\") print}' data\" u 1:2 w l" |
gnuplot --persist
it is possible to avoid ugly escaping by putting the processing commands
into a separate shell script.
On 16/01/2013 12:16, Thor Andreassen wrote:
> The only issue is if I want to connect data points
> separated by one of the undefined lines, see for example:
>
> echo "plot 'data' u 1:((strcol(3) eq 'A')? \$2 : 1/0)" | gnuplot
>
> [...]
>
--
Mikhail Kononets
Ph.D. Student
Marine Chemistry
Department of Chemistry and Molecular Biology
University of Gothenburg
Kemivagen 10
SE-412 96
Gothenburg, Sweden
office num.: +46-31-786-9063
mobile num.: +46-70-216-0936
e-mail: m.k...@ch...
mko...@gm...
|
|
From: Kai H. <kai...@gm...> - 2013-01-17 03:07:01
|
On 16 January 2013 18:50, Mikhail Kononets <mko...@gm...> wrote: > why not using 1/0 specification instead of '?': Sorry, I'm a bit of a gnuplot newbie. I asked the question upon http://stackoverflow.com/questions/14314895/ and my sources are upon https://github.com/kaihendry/laptemp gnuplot> help 1/0 Sorry, no help for '1/0' gnuplot> help ? Doesn't "1/0" mean one divided by zero? I also (erroneously, I guess) filed a bug upon http://sourceforge.net/tracker/?func=detail&aid=3600871&group_id=2055&atid=102055 which I've since closed. Many thanks, |
|
From: walter h. <wh...@bf...> - 2013-01-21 08:53:42
|
Am 16.01.2013 14:16, schrieb Thor Andreassen:
> On Wed, Jan 16, 2013 at 12:39:36PM +0100, Mikhail Kononets wrote:
>> you could use external data processing in this case, like:
>>
>> echo "plot \"< awk '{ if (\$3==\\\"A\\\") print}' data\" u 1:2 w l" | gnuplot --persist
>
> Right, this is another way to do it, thank you. Although I would prefer,
> and expect, that the script I listed would work.
>
> Thank you for your help.
>
> [...]
>
maybe it is a bit late but you can use awk etc also within a plot cmd like
plot "<awk 'file'"
i found it very handy while testing
re,
wh
|
|
From: Kai H. <kai...@gm...> - 2013-01-21 08:59:06
|
On 21 January 2013 16:53, walter harms <wh...@bf...> wrote: > maybe it is a bit late but you can use awk etc also within a plot cmd like > plot "<awk 'file'" > i found it very handy while testing I was using a similar approach https://github.com/kaihendry/laptemp/commit/863ea1de75b95ac0db19f656c5178e569a296cfd Problem with this is that lines won't join IIRC. |
|
From: Thor A. <ta...@to...> - 2013-01-16 13:16:12
|
On Wed, Jan 16, 2013 at 12:39:36PM +0100, Mikhail Kononets wrote:
> you could use external data processing in this case, like:
>
> echo "plot \"< awk '{ if (\$3==\\\"A\\\") print}' data\" u 1:2 w l" | gnuplot --persist
Right, this is another way to do it, thank you. Although I would prefer,
and expect, that the script I listed would work.
Thank you for your help.
[...]
--
best regards
Thor Andreassen
|