MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: ListPlot with missing values

  • To: mathgroup at smc.vnet.net
  • Subject: [mg22454] Re: ListPlot with missing values
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sat, 4 Mar 2000 02:26:27 -0500 (EST)
  • References: <892pd1$pj6@smc.vnet.net> <897ebc$5rc@smc.vnet.net> <89a79u$96g$1@dragonfly.wolfram.com> <89ibvi$n0k@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Roy,

First, the makings of a function:

alist = {{1, 1}, {2, 3}, {3, 5}, {4,}, {5, 6}, {6, 8}, {7,}, {8, 10}, {9,
12}}

{{1, 1}, {2, 3}, {3, 5}, {4, Null}, {5, 6}, {6, 8}, {7, Null}, {8, 10}, {9,
    12}}

bad = {_, Null}

{_, Null}

Split[alist, ! (MatchQ[#1, bad] || MatchQ[#2, bad]) &]

{{{1, 1}, {2, 3}, {3, 5}}, {{4, Null}}, {{5, 6}, {6, 8}}, {{7, Null}}, {{8,
      10}, {9, 12}}}

DeleteCases[%, {bad}]

{{{1, 1}, {2, 3}, {3, 5}}, {{5, 6}, {6, 8}}, {{8, 10}, {9, 12}}}

lines = Line /@ %

{Line[{{1, 1}, {2, 3}, {3, 5}}], Line[{{5, 6}, {6, 8}}],
  Line[{{8, 10}, {9, 12}}]}

Show[Graphics[%], Frame -> True ]

Now the function:

SplitListPlot[lst_, bad_, opts___?OptionQ] :=
Show[Graphics[
      Line /@ DeleteCases[
          Split[lst, ! (MatchQ[#1, bad] || MatchQ[#2, bad]) &],
          {bad}]
      ], opts ]

SplitListPlot[alist, {_, Null}, Frame -> True]

You will find that degenerate lines like Line[{{0,0}}] with only one
coordinate will show as points - this could be dealt with.

Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Roy Mendelssohn" <rmendels at pfeg.noaa.gov> wrote in message
news:89ibvi$n0k at smc.vnet.net...
> First, thanks to all who answered.  I clearly didn't explain the problem
> carefully enough.  Assume we are plotting a time series with missing
> data, and only want to conect consecutive points that have data, have
> blanks whenever a time point is missing, and still want points lined up
> correctly in time on the x axis.  If I just delete cases, then the
> endpoints of any missing segment will be connected, rather than being
> blank.
>
> In the example
>
> alist = {{1, 1}, {2, 3}, {3,5},{4,}, {5, 6}, {6,8},{7,}, {8,10},{9, 12}}
>
> I want a line joing the first three points, then a blank, then a line
> connecting the next two points, then a blank etc.
>
> The reason I mentioned the number of datapoints is because one solution
> is to draw a graph for each uninterrupted segment of the time series,
> and then overlay them.  This seems inelegant,because several hundred
> separate graphs might have to be drawn.
>
> If anyone else has other suggestions I would welcome them.
>
> -Roy M.
>
>



  • Prev by Date: official statement on Linux and Calculus WIZ
  • Next by Date: Re: Rearranging a tensor
  • Previous by thread: Re: Re: ListPlot with missing values
  • Next by thread: Re: ListPlot with missing values