6
$\begingroup$

This compares two curves, with a slider to control one parameter:

k = 8.617 10^-5; (*eV/K*)
nFD[ϵ_, μ_, t_] := 1/(E^((ϵ - μ)/(k t)) + 1);
g[ϵ_] := Sqrt[ϵ];
Manipulate[
 Plot[{g[ϵ], 
   g[ϵ]*nFD[ϵ, 1, t]}, {ϵ, 0, 2},
  PlotRange -> {{0, 2}, {0, 1.5}},
  GridLines -> {{1.0}, None}, 
  GridLinesStyle -> Directive[Dotted, Gray],
  AxesLabel -> {"ϵ", 
    "\!\(\*SubscriptBox[OverscriptBox[\(n\), \(_\)], \(FD\)]\)"}, 
  Filling -> {1 -> {2}, 2 -> Axis},
  Ticks -> {{{1, "μ"}}, Automatic},
  PlotLegends -> 
   Placed[{"g[ϵ]", 
     "g[ϵ]*\!\(\*SubscriptBox[OverscriptBox[\(n\), \(_\)], \
\(FD\)]\)[ϵ]"}, {{0.05, 0.98}, {0, 1}}]
  ], {{t, 1}, 1, 10^4}]

It works fine, except for one glitch: When the slider is all the way to the left, or almost all the way, both functions get cut off slightly to the right of the vertical dotted line, even though the x-axis continues farther. (Sometimes I have to move the slider right then left again to trigger it.) Here's a screen shot:

graphs cut off inappropriately

For slightly larger slider values, the functions appear properly drawn all the way to the right edge of the plot:

enter image description here

I have been unable to figure out why, or to find a workaround. Any thoughts, o sage ones?

$\endgroup$
  • $\begingroup$ It works perfectly fine in version 9. $\endgroup$ – wxffles Nov 14 '16 at 20:47
  • $\begingroup$ Interesting. Should have said I'm using 11.0.1.0 on OS X. $\endgroup$ – ibeatty Nov 14 '16 at 20:48
  • 1
    $\begingroup$ Same problem on 11.0.0 on Ubuntu 16.04. You could simplify the code a lot: with plot[t_] := Plot[{g[\[Epsilon]], g[\[Epsilon]]*nFD[\[Epsilon], 1, t]}, {\[Epsilon], 0, 2}, PlotRange -> {{0, 2}, {0, 1.5}}], the problem can be seen on plot[4] for example. Strangely enough, if you remove g[\[Epsilon]]*Chop@nFD[\[Epsilon], 1, t], the blue curve becomes normal. $\endgroup$ – anderstood Nov 14 '16 at 20:49
  • $\begingroup$ Indeed, Show is a possible workaround, but it makes niceties like legends and filling between curves much more awkward to manage. $\endgroup$ – ibeatty Nov 14 '16 at 21:17
  • $\begingroup$ @anderstood Aah, now I understand what you meant by simplifying! I thought you were talking about simplifying the computation with the Chop. I don't have time to edit the post right now, but will try to do that soon. Thanks. $\endgroup$ – ibeatty Nov 14 '16 at 22:03
5
$\begingroup$

The trick is to add Exclusions -> None to the Plot function parameters. Apparently, Mathematica interprets your second function as reaching a singularity point. If you extract last points from the original plot for t=1

plot = Plot[{g[\[Epsilon]], g[\[Epsilon]]*nFD[\[Epsilon], 1, 1]}, {\[Epsilon], 0, 2},PlotRange -> {{0, 2}, {0, 1.5}}]
Cases[plot, l_Line :> First@l, Infinity][[;; , -1]]
(* {{1.019, 1.00946}, {1.04011, 6.91909*10^-203}} *)

you will see that the second pair has a very small y coordinate. Potentially, this is where Mathematica decides it has reached a singularity point and stops rendering further. This helps graphs of not well-behaved functions to still look nice.

If you add Exclusions -> None, the kernel works fine, as well as the rendered graphics

plot = Plot[{g[\[Epsilon]], g[\[Epsilon]]*nFD[\[Epsilon], 1, 1]}, {\[Epsilon], 0, 2},Exclusions -> None,PlotRange -> {{0, 2}, {0, 1.5}}]
Cases[plot, l_Line :> First@l, Infinity][[;; , -1]]
(* {{2., 1.41421}, {2., 0.}} *)

enter image description here

$\endgroup$
  • $\begingroup$ Brilliant! I knew there had to be a sensible explanation for this behavior. Thanks $\endgroup$ – ibeatty Nov 15 '16 at 14:21
2
$\begingroup$

Mathematica has trouble making the plot in the range 0 <= t <= 17, so I recommend restricting the t control from entering that range. Doing so has very little qualitative effect on the plot because it is such a tiny part pf the total range.

Manipulate[
  Plot[
    {g[ϵ], g[ϵ] nFD[ϵ, 1, t]}, {ϵ, 0, 2},
    PlotRange -> {{0, 2.}, {0, 1.5}},
    GridLines -> {{1.}, None},
    GridLinesStyle -> Directive[Dotted, Gray], 
    AxesLabel -> {ϵ, Subscript[Overscript[n, _], FD]},
    Filling -> {1 -> {2}, 2 -> Axis},
    Ticks -> {{{1, "μ"}, {2, 2 "μ"}}, Automatic},
    PlotLegends ->
      Placed[
        {"g"[ϵ], "g"[ϵ] Subscript[Overscript[n, _], FD][ϵ]},
        {{0.05, 0.98}, {0, 1}}],
    ImageSize -> 480],
  {t, 20., 8000, 20, Appearance -> "Labeled", ImageSize -> 440}]

plot

Beside change the control, I have made a few tweaks that I think improve the labeling.

$\endgroup$
  • $\begingroup$ Do you know why it has trouble plotting for $0\leq t\leq 17$? $\endgroup$ – anderstood Nov 15 '16 at 0:39
  • $\begingroup$ @anderstood. The function nFD[ϵ, 1, t] has a discontinuity at 1. Mathematica often has trouble plotting functions near discontinuities. At the scale you are plotting at, it seems the whole interval from 1 to 17 is indistinguishable from 1 to the plotting algorithm. $\endgroup$ – m_goldberg Nov 15 '16 at 16:18

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.