3
$\begingroup$

I am trying to place the plot title somewhere neat, to the left of x=0.

  Plot[1/(1 + Exp[-x]), {x, -10, 10}, 
 PlotLabel -> 
  Framed@Pane[
    "F (x)=\!\(\*FractionBox[\(1\), \(1 + \*SuperscriptBox[\(e\), \
\(-x\)]\)]\)", Alignment -> Right]]

I tried this but it's still sticking at the top of figure, any help appreciated!

$\endgroup$

2 Answers 2

5
$\begingroup$

You can use Inset[] to add it to the graphics, instead it being a label:

Plot[1/(1 + Exp[-x]), {x, -10, 10}, 
 Epilog -> 
  Inset[Framed@
    Pane["F (x)=\!\(\*FractionBox[\(1\), \(1 + \
\*SuperscriptBox[\(e\), \(-x\)]\)]\)", Alignment -> Right],
   {-1.5, 1}, {1, 1}]]

enter image description here

FWIW, I rather prefer the look of TraditionalForm in this:

Plot[1/(1 + Exp[-x]), {x, -10, 10}, 
 Epilog -> Inset[Framed@
    Pane[HoldForm[F[x] == 1/(1 + E^-x)], Alignment -> Right],
   {-1.5, 1}, {1, 1}]]
$\endgroup$
3
$\begingroup$

You can wrap your label with another Framed with the options FrameStyle -> None and FrameMargins -> {{0, rightmargin}, {0,0}} with your choice of rightmargin:

Plot[1/(1 + Exp[-x]), {x, -10, 10}, 
 PlotLabel -> Framed[Framed[Pane[HoldForm[F[x] = 1/(1 + E^-x)], 
   Alignment -> Right]], 
   FrameStyle -> None, FrameMargins -> {{0, Scaled[.1]}, {0, 0}}]]

enter image description here

Use FrameMargins -> {{0, Scaled[.14]}, {0, Scaled[.05]}} to get

enter image description here

Update: An alternative way is to put the label in a dynamic, movable Epilog:

DynamicModule[{pt = Scaled[{.5, 1}]},
 Plot[1/(1 + Exp[-x]), {x, -10, 10},
  ImagePadding -> {{Automatic, Automatic}, {Automatic, Scaled[.05]}},
  PlotRangeClipping -> False,
  Epilog -> Dynamic[Locator[Dynamic[pt],
     Panel[HoldForm[F[x] = 1/(1 + E^-x)]],
     Background -> White, LocatorRegion -> Full]]]]

enter image description here

$\endgroup$
2
  • $\begingroup$ Isn't the TraditionalForm unnecessary? (It's applied by default here, I think.) $\endgroup$
    – Michael E2
    Commented Mar 12, 2019 at 16:40
  • $\begingroup$ Thank you @MichaelE2; good point. $\endgroup$
    – kglr
    Commented Mar 12, 2019 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.