Re: Seeking your advice: ListLinePlot with null values
- To: mathgroup at smc.vnet.net
- Subject: [mg107787] Re: Seeking your advice: ListLinePlot with null values
- From: Mark McClure <mcmcclur at unca.edu>
- Date: Fri, 26 Feb 2010 04:05:17 -0500 (EST)
- References: <9136758C31050F45ACFF7DE00CFAE719370AA4F8DA@EVS3.ColoState.EDU>
On Thu, Feb 25, 2010 at 9:10 PM, Chui,Helena <H.Chui at colostate.edu> wrote:
> I'm new to Mathematica and have found your class notes very helpful. I would
> really appreciate it if you would be able to help me out plotting data with null values.
>
> I want a plot with quadratic spline interpolation to fit the data. But with the missing
> values indicated by "null," the plot turns out to be straight lines joining the dots.
> Do you happen to know how to have quadratic spline interpolation with null
> values in the data?
I assume that your data is defined at the points 1,2,3,...,30 but that
you have no values at positions 14 and 17. I suggest that you replace
your data {x1,x2,x3,...,x30} with data of the form
{{1,x1},{2,x2},{3,x3},...{30,x30}}. Of course, the points {14,Null}
and {17,Null} will appear but they can be easily deleted.
ListLinePlot will then work as desired. You can automate the process
like so:
(* Your input data *)
data = {1.31332399, 0.33851347, 2.36370295, 2.38889243,
0.41408191, -0.56072862, 3.46446086, -2.51034966, -2.48516018, -2.4599707,
1.56521878, -1.40959175, -2.38440227, Null, -2.33402331, 0.69116617, Null,
2.74154512, -2.2332654, -1.20807592, -2.18288644,
1.84230304, -1.13250748, -0.10731801, -0.08212853, -1.05693905, \
-2.03174957, -2.00656009, 0.01862939, 9.04381887};
(* Place in (x,y) form *)
data = Transpose[{Range[Length[data]], data}]
(* Grab only those data points with numeric entries. *)
data = Select[data, NumericQ[Last[#]] &];
(* And plot *)
ListLinePlot[data, InterpolationOrder -> 2]
If you find that you have a lot of these kinds of questions, I highly
recommend the Mathematica discussion group, mathgroup. I have
forwarded this message there, since it acts as a nice repository of
answers. You can browse the discussions in a variety of places,
including Google Groups:
http://groups.google.com/group/comp.soft-sys.math.mathematica/topics
Hope that helps,
Mark McClure