14
$\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$

2 Answers 2

18
$\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$
2
  • $\begingroup$ Since only the $y$-range is being changed, one could also do the shorter Show[gr, PlotRange -> {0, 0.4}]. $\endgroup$ Commented Oct 17, 2012 at 3:23
  • $\begingroup$ @J.M. added to the code. Thanks. $\endgroup$
    – halirutan
    Commented Oct 17, 2012 at 7:57
2
$\begingroup$

Adding the option ClippingStyle -> False gives the desired result:

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

enter image description here

See: this answer by Coolwater

$\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.