I'm trying to draw a plot of the Fermi-Dirac distribution,

enter image description here

for which I'd like to show a few lines of varied temperate (T). My code works for this, except for zero temperature, it results in a Dimension too large error from pgfplots. Is there a way to resolve this while keeping the real value of the Boltzman constant, k_B, in electron volts?





    xlabel=$\frac{mv^2}{2k_BT}$ (eV),
    legend entries={0 K,100 K,1000 K,10000 K},
    x tick style={color=black},
    y tick style={color=black},
    xtick pos=left,
    ytick pos=left,
\addplot[samples=50,black] {(1/((exp((x)/(80.617e-5))+1))};
\addplot[samples=50,blue,dashed] {(1/((exp((x)/(8.617e-3))+1))};
\addplot[samples=50,red,dashed] {(1/((exp((x)/(8.617e-2))+1))};
\addplot[samples=50,green,dashed] {(1/((exp((x)/(8.617e-1))+1))};


This code compiles but 80.617e-5 should be 8.617e-5 which breaks the code. I've tried varying/removing xmin, xmax with no success. I also read in a few answers something to do with fpu but this didn't seem to work for me or is no longer required? restrict x to domain did not seem to help, though I could be using it wrong.

enter image description here

  • TeX does not really support floating point numbers. Tikz fakes it using dimen registers (fixed point) and converting everything into text. To do it right you should compute the numbers elsewhere and import them using plgplotstable. – John Kormylo Jun 22 '15 at 12:26

The root cause is a deficiency in the TeX based floating point unit employed by pgfplots. An intermediate result requires to compute

%\tracingmacros=2 \tracingcommands=2

which reaches some internal limit. I accept that as bug report and will see if I can fix it.

For the time being, you can consider to compile your example with

  • pgfplots in version 1.12 or newer and
  • lualatex .

This will work out of the box (as soon as you fix the syntax error in your first \addplot expression, there is a round brace too much in it).

| improve this answer | |
  • I must have added a set of parentheses when trying to get it to work. It works, as you said, with LuaLaTeX, pgfplots v1.12 and \addplot[samples=250,black] {1/(exp((x)/(8.617e-5))+1)}; I'll have to read up on how Lua handles the situation for my knowledge. – Christopher Jun 23 '15 at 7:35
  • Ok, great. If I am not mistaken, there is a hidden question like "why does lua help here" behind your comment. If so, the answer would be: pgfplots comes with a partial reimplementation in lua and switches to lua whenever it can. See lua backend in the pgfplots reference manual for details pgfplots.sourceforge.net – Christian Feuersänger Jun 23 '15 at 18:30

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.