1
$\begingroup$

I want to shade the region in the right/Left side of a vertical line with gray colour in ListPlot. For example I write a code like this:

abc = {{0.98, 0}, {0.98, 6}, {0.98, 15}};
ListPlot[{abc}  , Joined -> True, PlotRange -> {{0.6, 1}, {0, 10}}, 
 PlotRangeClipping -> True, AspectRatio -> 1, Frame -> True, 
 BaseStyle -> Directive[Bold, FontFamily -> "Times", 18], 
 FrameStyle -> Directive[Black, Thick], ImageSize -> 400, 
 PlotStyle -> {Directive[Black, DotDashed, Thick]}, 
 FrameLabel -> {"x", "y"}, Axes -> False, Filling -> Axis]

But I get the plot like this-enter image description here

So, I need help to shade the area in left or right side of this vertical straight line with gray colour.

$\endgroup$
2
  • 3
    $\begingroup$ Something like this: ListPlot[{{0., 0.}, {0.3, 0.6}, {0.7, 0.4}, {0.9, 0.3}, {0.99, 0.1}}, AspectRatio -> Automatic, PlotRange -> {{0, 1}, {0, 1}}, PlotRangePadding -> Scaled[0.05], Prolog -> {{Opacity[0.7, Gray], HalfPlane[{0.95, 0}, {0, 1}, {-1, 0}]}, {Directive[Black, DotDashed, Thick], InfiniteLine[{0.95, 0}, {0, 1}]}}]? $\endgroup$ Commented Jul 24, 2022 at 13:43
  • $\begingroup$ Thanks, it works fine. $\endgroup$ Commented Jul 24, 2022 at 13:52

1 Answer 1

1
$\begingroup$

You may use "Epilog" to shade these regions. E.g.:

ListPlot[{abc, {{0.6, 0}, {0.6, 10}}}, Joined -> True, 
 PlotRange -> {{0.6, 1}, {0, 10}}, PlotRangeClipping -> True, 
 AspectRatio -> 1, Frame -> True, 
 BaseStyle -> Directive[Bold, FontFamily -> "Times", 18], 
 FrameStyle -> Directive[Black, Thick], ImageSize -> 400, 
 PlotStyle -> {Directive[Black, DotDashed, Thick]}, 
 FrameLabel -> {"x", "y"}, Axes -> False, 
 Epilog -> {Opacity[0.5], LightGray, Rectangle[{0.6, 0}, {0.98, 10}], 
   Gray, Rectangle[{0.98, 0}, {1, 10}]}]

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.