4

I will give an example of a regular Plot, but I also need this to work for a ParametricPlot. Say I have

plt1=Plot[Sin[x],{x,0,2π}]

I now want to add two vertical lines, one at x=3π/4 abd on at x=5π/4. In addition, I want to shade the region between those two lines. My initial idea was to use ParametricPlot to draw the line, and I hoped it would have a Fillingoption similar to that of Plot, but it does not.

The next idea was to use

plt2=RegionPlot[3π/4<x<5π/4,{x,0,2π},{y,-1.5,1.5}]

where I deliberately draw the box a bit larger on the y-coordinate, since I want it to be clipped at the PlotRange of plt1. Now I thought I combine both plots by

Show[plt1,plt2]

which gives

enter image description here

And this es exactly as I want it, with the one exception that

  1. the shaded region contains that weird mesh of thin lines.

This problem disappears if I show them in opposite order

Show[plt2, plt1]

which gives

enter image description here

But it also introduces the new problems that

  1. the plot range would have to be manually adjusted
  2. the plot is now shown with these boxed axes style, and I am not sure how to change it to the usual one of Plot.

Problem 2. is admittedly the lesser problem. But if someone could help me fix preferably 1. or otherwise 3. that would be great! Thanks!

Britzel
  • 663
  • 3
  • 10

1 Answers1

4

Prolog is useful here.

Plot[Sin[x], {x, 0, 2 π}, 
 Prolog -> {LightBlue, Rectangle[{3 π/4, -2}, {5 π/4, 2}]}]

enter image description here

Suba Thomas
  • 8,716
  • 1
  • 17
  • 32
  • Nice and simple solution! Thanks a lot! – Britzel Jul 17 '20 at 15:49
  • If you want to pimp the box in your answer a bit, use: Prolog -> {Opacity[.2], RGBColor[0.368417, 0.506779, 0.709798], EdgeForm[Directive[Thin, RGBColor[0.368417, 0.506779, 0.709798]]], Rectangle[{3 π/4, -2}, {5 π/4, 2}]}. ; ) That is the same blue tone as the plot line, and it has the vertical lines left and right. Thanks again! – Britzel Jul 17 '20 at 16:11
  • Sure, 'pimp' it to your heart's content. :) And, in case you didn't know, the default plot style is easier remembered as ColorData[97, 1]. – Suba Thomas Jul 17 '20 at 16:52
  • Didn't know! Thanks once more. (I knew ColorData[97,"ColorList"] and then copy-pasted the desired color so far.) – Britzel Jul 17 '20 at 18:38