13
$\begingroup$

In a non-joined ListPlot one can specify that a filling line is shown for each point:

ListPlot[Table[{x, Exp[-x^2]}, {x, -2, 2, 0.1}], Filling -> Axis, FillingStyle -> Red]

1

But if the points are out of the plot range, the filling line no longer appears:

ListPlot[Table[{x, Exp[-x^2]}, {x, -2, 2, 0.1}], Filling -> Axis, FillingStyle -> Red, 
  PlotRange -> {0, 0.5}]

2

Is there any way to still show the line up the plot range, to show that there is a point there (but you just can't see it)? Or must I draw the lines myself with a Prolog?

$\endgroup$
17
$\begingroup$

One solution is to use ListPlot with PlotRange->All (in your example you don't need it) and crop the region afterwards by calling Show:

gr = ListPlot[Table[{x, Exp[-x^2]}, {x, -2, 2, 0.1}], Filling -> Axis,
    FillingStyle -> Red, PlotRange -> All];
Show[gr, PlotRange -> {Automatic, {0, 0.4}}]
(* or shorter Show[gr, PlotRange -> {0, 0.4}] *)

Mathematica graphics

$\endgroup$
  • $\begingroup$ Since only the $y$-range is being changed, one could also do the shorter Show[gr, PlotRange -> {0, 0.4}]. $\endgroup$ – J. M. will be back soon Oct 17 '12 at 3:23
  • $\begingroup$ @J.M. added to the code. Thanks. $\endgroup$ – halirutan Oct 17 '12 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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