5
$\begingroup$

This is motivated by this question.

Consider the list

list={0.2, 0.5, 0.7};

If I plot the data using ListLinePlot I get a curve like this

Plot1

If I now apply interpolation using

ListLinePlot[{0., 0.2, 0., 0., 0.5, 0., 0., 0.7, 0.}, 
 InterpolationOrder -> 2]

I get

Plot2

Now I wish to find the list which includes the interpolated values along with the zero values between 3 to 4 and 6 to 7 to generate Plot2.

How can I do this?

$\endgroup$
0

1 Answer 1

8
$\begingroup$

Update: A single list of points with negative y-values clipped to 0:

llp = ListLinePlot[{0., 0.2, 0., 0., 0.5, 0., 0., 0.7, 0.}, 
    InterpolationOrder -> 2,  PlotRange -> {-.2, 1}];
clippedpoints =  Cases[llp,  Line[x_] :> 
  Transpose[{#, Clip[#2, {0, Infinity}]} & @@ Transpose[x]], Infinity]

Show[llp, ListPlot[clippedpoints, PlotStyle -> Directive[Red, PointSize[.01]]], 
   PlotRange -> All]

enter image description here

True


Original answer:

llp = ListLinePlot[{0., 0.2, 0., 0., 0.5, 0., 0., 0.7, 0.}, 
  InterpolationOrder -> 2, PlotStyle -> Thick, PlotRange -> {0, All}]; 
points = Cases[llp, Line[x__] :> x, Infinity];

points // Short[#, 4] &

{{{1.,0.},{1.0234,0.00634228},{1.04853,0.0131544},{1.07539,0.0204362},{1.10399,0.0281879},<<45>>,{2.92412,0.0156563},{2.96203,0.00766473},{3.,3.46945*10^-18},{3.,0.}},{{<<18>>,0.},<<52>>},{<<1>>}}

Show[llp, ListPlot[points, PlotStyle -> Directive[Red, PointSize[.01]]], 
  PlotRange -> All]

enter image description here

$\endgroup$
6
  • $\begingroup$ The original plot doesn't have any negative value. The negative values in your plot should be truncated to 0 as they are in the original list. $\endgroup$
    – user36426
    Jan 17, 2018 at 20:06
  • $\begingroup$ @Majis, please see the update. $\endgroup$
    – kglr
    Jan 17, 2018 at 20:12
  • $\begingroup$ The plot is now truncated but the truncated points (zero values) are not shown. $\endgroup$
    – user36426
    Jan 17, 2018 at 20:18
  • $\begingroup$ @Majis, there are no zero values in your original plot (due to the default plot range in version 11 you get a picture that does not show negative values). You can see that clearly if you remove the axes: ListLinePlot[{0., 0.2, 0., 0., 0.5, 0., 0., 0.7, 0.}, InterpolationOrder -> 2, Axes->False] $\endgroup$
    – kglr
    Jan 17, 2018 at 20:35
  • $\begingroup$ Yes, true. But I need the zero values as well. $\endgroup$
    – user36426
    Jan 17, 2018 at 20:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.