# Mathematica equivalent to gnuplot's fsteps option?

In a ListLinePlot I can set InterpolationOrder -> 0 to get the equivalent of gnuplot's steps option, where the stepped line for each two points steps at the second point. Is there a Mma equivalent to gnuplot's fsteps option, where the stepped line for each two points steps at the first point? (In tikz terminology, I want |- instead of -| to connect successive points.)

Example application: Verhulst diagrams.

Edit 1:

Answers to the question referenced by @MarcoB show that ListLinePlot with InterpolationOrder->0 constructs a standard Manhatten path (alternating horizontal and vertical segments between points). This is equivalent to gnuplot's steps option. I'm after the equivalent of gnuplot's fsteps option: alternating vertical and horizontal segments.

To be clear: I am not asking how to produce this plot by creating new data through list manipulations. (See posts on cobweb plots with Mma for that.) I'm looking for built-in Mma functionality. (I accept that this may not exist.)

Edit 2:

logisticPath = NestList[2.75*#*(1 - #) &, 0.4, 10]
ListStepPlot[Transpose[{logisticPath, logisticPath}], "Left",
PlotRange -> All,
Prolog -> Line[{{0.4, 0.4}, {0.8, 0.8}}]]


Produces

This is almost right. I just need to get rid of that initial segment, which is outside the data. What I want looks like this (using the same data):

cobwebPoints = Partition[Riffle[logisticPath, logisticPath], 2, 1]
ListLinePlot[cobwebPoints, PlotRange -> All,
Prolog -> {Line[{{0, 0}, {1, 1}}]},
PlotRange -> All]


• Strongly related: How can the behavior of InterpolationOrder->0 be controlled? Jul 14, 2015 at 15:09
• @MarcoB I think the answers to your referenced question shows that my first sentence is correct but does not explain how to get fsteps behavior. Correct me if I'm wrong.
– Alan
Jul 14, 2015 at 23:01
• Alan, I think @MichaelE2's answer in that post does provide you a method to get the fsteps behavior, at least as far as I understand what that behavior is. Take a look at my answer below, and let me know if I am misunderstanding. If, however, by "built-in MMA functionality" you mean an option to ListLinePlot, then the answer is in fact negative. However, you could just start considering Michael's helper functions "built-in" from now on :-) Jul 15, 2015 at 5:29
• Mathematica v10.2 (just released) brings a new function: ListStepPlot. See the step argument, which can take Right, Left and Center values. Jul 15, 2015 at 5:39
• @kirma Had I seen that comment I might not have joined in voting to close. I think that would make an excellent answers that is appropriate here but not for the other question. If you would like to post that as an answer I shall reopen this. Jul 15, 2015 at 9:29

Fresh v10.2 introduces ListStepPlot which provides just the right facility for this task:

pts = {{1.81515, 1.46912}, {4.99276, 1.87137}, {9.12065,
6.83238}, {9.9288, 5.30858}, {5.6387, 4.30558}, {4.45562,
6.44036}, {0.0721842, 9.82819}, {2.88155, 4.80602}, {7.01912,
9.91699}, {0.277599, 5.36962}};

ListStepPlot[SortBy[First][pts], Left, Mesh -> Full, MeshStyle -> Red]


• I was going to suggest this. +1 Jul 15, 2015 at 12:53

Alan, I think you can use Michael's stepFunctions from the answer I linked to in the comments to solve your problem. Here is a link to MichaelE2's original answer: https://mathematica.stackexchange.com/a/30103/27951. Below is an adaptation to your problem using the step* functions defined in Michael's original answer. Note that this approach requires no modification to your existing points.

First of all, let's have some random points to play with:

pts = {{1.81515, 1.46912}, {4.99276, 1.87137}, {9.12065, 6.83238}, {9.9288, 5.30858},
{5.6387, 4.30558}, {4.45562, 6.44036}, {0.0721842, 9.82819}, {2.88155, 4.80602},
{7.01912, 9.91699}, {0.277599, 5.36962}};

ListLinePlot[
SortBy[First][pts],
InterpolationOrder -> 0, PlotRange -> All,
Epilog -> {PointSize[0.02], Red, Point@pts}
]


Above is the native behavior of InterpolationOrder -> 0 that is undesirable to you in this case.

It seems to me that the function you are looking for is stepFloor in the post linked above. You use it as follows:

Plot[
stepFloor[pts][x], {x, 0, 11},
Epilog -> {PointSize[0.02], Red, Point@pts}
]


You can also compare all the functions Michael had proposed. Note that stepCeiling repoduces the behavior of the native InterpolationOrder -> 0 in ListLinePlot.

original = ListLinePlot[
Sort@pts,
InterpolationOrder -> 0,
Epilog -> {PointSize[0.02], Red, Point@pts},
PlotLegends -> LineLegend[
{Blue, Directive[Black, Dashed], Directive[Darker@Green, Dashed], Directive[Darker@Red, Dashed]},
{"original", "stepFloor", "stepCeiling", "stepNearest"}
]
];

floor = Plot[stepFloor[pts][x], {x, -1, 10}, PlotStyle -> {Thick, Dashed, Black}];
ceiling = Plot[stepCeiling[pts][x], {x, -1, 10}, PlotStyle -> {Thick, Dashed, Darker@Green}];
nearest = Plot[stepNearest[pts][x], {x, -1, 10}, PlotStyle -> {Thick, Dashed, Darker@Red}];

Show[original, floor, ceiling, nearest]


One way is to simply shift the data:

data = {{0, 1}, {1, -1}, {2, 2}, {3, 1}, {4, 3/2}};
ListLinePlot[ data, InterpolationOrder -> 0]
ListLinePlot[
Transpose[{data[[All, 1]],
Append[data[[All, 2]][[2 ;;]], data[[-1, 2]]]}],
InterpolationOrder -> 0]