1
$\begingroup$

I have a list such as here:

list1 = {{-(5/4), 3}, {-(3/4), 2}, {1/4, 6}, {3/4, 5}};

My desire is to have a plot similar to (just in shape not in data) enter image description here

however when I use of ListLinePlot, I just get a plot same as : enter image description here

I guess I have to insert some zeros between my main data in list? if it is correct, how many zeros are needed?

$\endgroup$
3
  • 1
    $\begingroup$ Does the option Filling -> Axis not do what you want? It's the very first example in the ListPlot documentation. $\endgroup$ Oct 26, 2015 at 9:42
  • $\begingroup$ Yes, But it doesn't satisfy all aim, because Filling just plots lines bellow points, I wanted to have zero horizontal line at the bottom of the plot as the first plot. $\endgroup$ Oct 26, 2015 at 9:51
  • $\begingroup$ If it gets more complicated than this (I'm thinking of the horizontal red line), you can also build the graphics directly from Line primitives. Working with graphics primitives in Mathematica is easier than one might imagine. :-) reference.wolfram.com/language/tutorial/… $\endgroup$
    – Szabolcs
    Oct 26, 2015 at 11:25

2 Answers 2

8
$\begingroup$

Consider setting a custom gridline:

ListPlot[list1, PlotStyle -> White, Filling -> Bottom, 
 FillingStyle -> Directive[Thick, Red], GridLines -> {None, {0}}, 
 GridLinesStyle -> Directive[Thick, Red]]

enter image description here

The one difference from your picture is that a gridline goes all the way across the plot area. If it is important to you that the horizontal line ends at the extremes of your data set, then the following alternative might be what you want:

ListPlot[list1, PlotStyle -> White, Filling -> Bottom, 
 FillingStyle -> Directive[Thick, Red], 
 Epilog -> {Thick, Red, Line[{{-5/4, 0}, {3/4, 0}}]}]

enter image description here

I would note that ListLinePlot is designed to join the points together; it is equivalent to ListPlot with the Joined option set to True. If you want disjoint points, you need ListPlot, with the Joined option set to False, which is the default.

$\endgroup$
4
$\begingroup$
list1 = {{-(5/4), 3}, {-(3/4), 2}, {1/4, 6}, {3/4, 5}};
xLim = {Min[#], Max[#]} &[list1[[All, 1]]];

zeroLine = Plot[0, {x,Min@xLim, Max@xLim}, PlotStyle -> {Thick, Red}];
    listPlot = ListPlot[list1, Filling -> Axis, PlotStyle -> {Thick, Red}];
Show[zeroLine, listPlot, PlotRange -> Automatic]

enter image description here

$\endgroup$

Your Answer

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

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