PlotStyle for GridLines

I have:

Plot[x^2,{x, 0, 5},GridLines->{{3,4}},PlotRange->{5,30},PlotStyle->{Black,Dotted,Thickness[0.003]}]


How to make these two vertical lines in style {Black,Dotted,Thickness[0.003]}? Or maybe there is some other way (without GridLines) to plot these vertical lines, but not using ContourPlot.

• Could use GridLinesStyle -> {{Black, Dotted, Thickness[0.003]}, None} Jun 14 at 0:15
• It works great, thanks! Jun 14 at 0:37

styles = Directive[Black, Dotted, Thickness[0.003], Opacity[1]];
Plot[x^2, {x, 0, 5}, GridLines -> {{{3, styles}, {4, styles}}},
PlotRange -> {5, 30}, PlotStyle -> {Black, Dotted, Thickness[0.003]}]


• Thanks. Nonetheless these vertical lines are gray not black for me. Jun 14 at 0:40
• @misha.physics This is the feature of opacity instead of gray,just add Opacity[1]. Jun 14 at 0:45

Another way (without GridLines) is use Epilog or Prolog. An advantage of this is grid lines can be added to the plot with the simplest GridLines->Automatic option without affecting the the vertical lines. Here is an example that uses color, thickness and dashing to distinguish the function, the grid lines and the vertical lines.

vlines = {Black, Dotted, Thickness[0.005],
InfiniteLine[{#, 0}, {0, 1}] & /@ {3, 4}};

Plot[x^2, {x, 0, 5}, GridLines -> Automatic,
PlotRange -> {5, 30}, Prolog -> vlines]