2
$\begingroup$

I am trying to add vertical lines as markers in a LogPlot. When I am doing this in a normal Plot works fine. When I change to LogPlot the lines start from a value of y=1 and not from 0,01 as I have defined them. Does someone know how can I fix it?

line1 = Line[{{10*10^9, 0.01}, {10*10^9, 2}}];
line2 = Line[{{30*10^9, 0.01}, {30*10^9, 2}}];
line3 = Line[{{200*10^9, 0.01}, {200*10^9, 2}}];
lineStyle = {Black, Dashed};

Plot[dw //. {h -> 2, vs -> 200, H -> 5}, {EE, 1*10^9, 300*10^9}, 
 AxesOrigin -> {0, 0.01}, Frame -> {True, True, True, True}, 
 AspectRatio -> 1, PlotStyle -> {{Blue}}, 
 BaseStyle -> {FontSize -> 12}, 
 Epilog -> {Directive[lineStyle], line1, line2, line3}, 
 FrameTicks -> {{#, 10^-9 #} & /@ 
     FindDivisions[{1*10^9, 300*10^9, 10}, 10] // N, Automatic}]

enter image description here

LogPlot[dw //. {h -> 2, vs -> 200, H -> 5}, {EE, 1*10^9, 300*10^9}, 
     AxesOrigin -> {0, 0.01}, Frame -> {True, True, True, True}, 
     AspectRatio -> 1, PlotStyle -> {{Blue}}, 
     BaseStyle -> {FontSize -> 12}, 
     Epilog -> {Directive[lineStyle], line1, line2, line3}, 
     FrameTicks -> {{#, 10^-9 #} & /@ 
         FindDivisions[{1*10^9, 300*10^9, 10}, 10] // N, Automatic}]

enter image description here

$\endgroup$
  • $\begingroup$ Can you include data for dw? $\endgroup$ – MarcoB Mar 1 '16 at 7:55
  • 1
    $\begingroup$ Why not use GridLines instead to mark the verticals? $\endgroup$ – J. M. is away Mar 1 '16 at 8:25
2
$\begingroup$

You need to scale the y-coordinate of the Line objects via Log. Notice that the lines start near y=1, this is because E^0.01=1.01.

You can modify your original lines by a replacement rule,

LogPlot[dw //. {h -> 2, vs -> 200, H -> 5}, {EE, 1*10^9, 300*10^9},
 AxesOrigin -> {0, 0.01}, Frame -> {True, True, True, True},
 AspectRatio -> 1, PlotStyle -> {{Blue}},
 BaseStyle -> {FontSize -> 12},
 Epilog -> {Directive[lineStyle], {line1, line2, line3} /. 
    Line[{{a_, b_}, {c_, d_}}] :> Line[{{a, Log@b}, {c, Log@d}}]},
 FrameTicks -> {{#, 10^-9 #} & /@ 
     FindDivisions[{1*10^9, 300*10^9, 10}, 10] // N, Automatic},
 PlotRange -> {{0, 300 10^9}, {0, 800}}]

enter image description here

or by using MapAt,

LogPlot[dw //. {h -> 2, vs -> 200, H -> 5}, {EE, 1*10^9, 300*10^9},
 AxesOrigin -> {0, 0.01}, Frame -> {True, True, True, True},
 AspectRatio -> 1, PlotStyle -> {{Blue}},
 BaseStyle -> {FontSize -> 12},
 Epilog -> {Directive[lineStyle], 
   MapAt[Log, {line1, line2, line3}, {All, 1, All, 2}]},
 FrameTicks -> {{#, 10^-9 #} & /@ 
     FindDivisions[{1*10^9, 300*10^9, 10}, 10] // N, Automatic},
 PlotRange -> {{0, 300 10^9}, {0, 800}}]

which gives the same result as above.

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