2
$\begingroup$

I have:

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

enter image description here

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.

$\endgroup$
2
  • 2
    $\begingroup$ Could use GridLinesStyle -> {{Black, Dotted, Thickness[0.003]}, None} $\endgroup$
    – Carl Woll
    Jun 14 at 0:15
  • $\begingroup$ It works great, thanks! $\endgroup$ Jun 14 at 0:37

2 Answers 2

6
$\begingroup$
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]}]

enter image description here

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

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]

enter image description here

$\endgroup$

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.