When trying to Plot the function

1/(1 + E^(((e + Quantity[-7.05, "Electronvolts"]) 
  *(Quantity[1, 1/("BoltzmannConstant")]))/T))

I get an incorrect plot looking likeincorrect Plot

However, if I first evaluate the points with Table and then use ListLinePlot it works as expected

correct Table@ListPlot

  • 2
    $\begingroup$ I'm not sure why you want to keep the units in the definition of f, but the following works: f[e_, T_] := 1/(1 + E^(((e + -7.05)*1)/T)). A good start when Plot returns an empty plot is to evaluate the function for some arbitrary values. Try and you'll understand why nothing plots. $\endgroup$
    – anderstood
    Mar 27, 2018 at 20:27
  • $\begingroup$ If you really must have units: With[{T = 5000}, Plot[1/(1 + E^(((Quantity[e, "Electronvolts"] + Quantity[-7.05, "Electronvolts"])*(Quantity[1, 1/("BoltzmannConstant")]))/Quantity[T, "Kelvins"])) // Evaluate, {e, 1, 20}]] $\endgroup$ Mar 28, 2018 at 1:13
  • 1
    $\begingroup$ @anderstood Whenever Plot returns nothing I always evaluate the function for arbitrary values. That's why, after Plot failed, I replaced Plot with Table. As you can see, evaluating the function for arbitrary values in Table works. And when I ListPlot those arbitrary values, the function works. My question was why Plot fails when the function successfully evaluates for arbitrary values. $\endgroup$
    – Max Coplan
    Mar 28, 2018 at 10:35

1 Answer 1


I think a general fix might be using a wrapper function to add the units:

fp[t_] := f[Quantity[t, "seconds"]]
Plot[fp[t], {t, 0, 0.004}]
(* instead of *)
Plot[f[t], {t, Quantity[0.0, "Seconds"], Quantity[0.004, "Seconds"]}]

The problem seems to be that Plot does not always pass the parameter to f with units. It seems like Echos are able to show what happens:

Plot[Echo[f[Echo[t]]], {t, Quantity[0.0, "Seconds"], Quantity[0.004, "Seconds"]}]

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.