3
$\begingroup$

I want to draw some auxiliary lines for typical values of the function in my graph like these blue dashed lines:
auxiliary lines

Also, I want to put the values of the lines by the lines like above one.

Do you know any smart and easy way to achieve these rather than using GridLine options many times manually?

The following is what I did and got, and not cool:

f[x_] := x/E^x;
Plot[f[x], {x, -2.5, 10}, GridLines -> {{{1, {Blue, Dashed}}}, {{f[1], {Blue, Dashed}}}}]

enter image description here

$\endgroup$
3
$\begingroup$

A tiny bit of modification on JasonB's answer

Plot[f[x], {x, -2.5, 10}, Ticks -> {{1}, {1/E}}, 
 GridLines -> Automatic, PlotStyle -> Black, AxesLabel -> {x, y},  
 Epilog -> {AbsolutePointSize[5], Point /@ {{1, 0}, {0, f[1]}}, Blue, 
   Point[{1, f[1]}], Dashed, 
   Line[{{{1, 0}, {1, f[1]}}, {{0, f[1]}, {1, f[1]}}}]}]

enter image description here

$\endgroup$
5
$\begingroup$

You can supply any Graphics primitives directly to the Plot using Epilog

Plot[f[x], {x, -2.5, 10}, 
 Epilog -> {Blue, Thick, Dashed, 
   Line[{{{1, 0}, {1, f[1]}}, {{0, f[1]}, {1, f[1]}}}]}]

Mathematica graphics

For your plot you can also put those point labels in using the Text graphics primitive, like Epilog -> {Text[Style["1/e", 13], {-.4, f[1]}], Blue, Thick, Dashed, Line[...]}

$\endgroup$
  • $\begingroup$ I don't get it... You are a postdoc again? :) $\endgroup$ – BlacKow Jun 24 '16 at 14:32
  • $\begingroup$ @BlacKow, he just wanted his old name back, tho Kuba had previously proposed "JasonB is me", but belatedly. $\endgroup$ – J. M.'s technical difficulties Jun 24 '16 at 14:36
  • 1
    $\begingroup$ @BlacKow - I couldn't handle the real world so I went back to academia.... And if I go for a silly name again it will be "American Pie's Jason Biggs" $\endgroup$ – Jason B. Jun 24 '16 at 14:38
5
$\begingroup$

For the fun of reproducing the original picture somewhat faithfully (yes, I can't seem to focus on real work this morning...):

f[x_] := x/E^x;
Plot[
 f[x], {x, -2.5, 10},
 Ticks -> {
   {0, 1},
   {{1/E, Row[{Style["1/", FontFamily -> "Times"], Style["e", FontFamily -> "Times", Italic]}]}}
 },
 TicksStyle -> Directive[Black, 12],
 PlotRange -> {{-1.2, 5.2}, {-0.9, 0.9}}, PlotRangePadding -> None,
 PlotStyle -> Black,
 GridLines -> {Range[-1, 5], Range[-1, 1, 0.5]},
 Epilog -> {
   Inset[Style["y = xe^(-x)", Bold, Italic, FontFamily -> "Times", 12], {3.7, 0.57}],
   PointSize[0.015], Point[{{0, 1/E}, {1, 0}}],
   {Blue, Point[{1, 1/E}]},
   Arrowheads[.035], Arrow[{{0, 0}, {0, 0.9}}], 
   Arrow[{{0, 0}, {5.2, 0}}],
   Inset[Style["0", 12], {0.14, -.073}],
   Inset[Style["x", Italic, FontFamily -> "Times", 14], {5.1, -0.073}],
   Inset[Style["y", Italic, FontFamily -> "Times", 14], {-0.2, 0.85}],
   Blue, Dashed, Line[{{0, 1/E}, {1, 1/E}}], Line[{{1, 0}, {1, f[1]}}],
 },
 AspectRatio -> 0.75
]

Mathematica graphics

$\endgroup$
  • 1
    $\begingroup$ no points... hehe $\endgroup$ – BlacKow Jun 24 '16 at 14:52
  • $\begingroup$ @BlacKow Ha! Forgot those! Thank you, you saved me from going back to work :-) $\endgroup$ – MarcoB Jun 24 '16 at 14:54
  • $\begingroup$ Still no blue dot... $\endgroup$ – BlacKow Jun 24 '16 at 14:58
  • $\begingroup$ ...and the label too. ;) $\endgroup$ – J. M.'s technical difficulties Jun 24 '16 at 14:58
  • 3
    $\begingroup$ @J.M. I feel accomplished now. I'd love to put that title on my résumé, but I'm afraid it may raise some eyebrows at my day job :-) $\endgroup$ – MarcoB Jun 24 '16 at 15:37

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.