Is there an elegant way to plot gamma function (or some similar non-elementary function),


via TikZ or pgfplots? The graph I have in mind is something similar to the following one,


The only solution that falls to my mind is the calculation of a list of coordinates (x,\Gamma(x)) with some other (non-TeX) software and then plotting those, but I would like to know if it is possible to avoid this path.

  • 4
    Hello. Have you tried searching this forum (or anywhere else on the web) for ways how to plot a function in LaTeX? – yo' Jan 20 '15 at 21:41
  • TikZ has a set of built-in (predefined) elementary functions (such as exp, ln, sin, etc.) so there is no problem with those. I'm note sure if there is some other way to draw \Gamma(x), apart from e.g. generating the coordinates (x,\Gamma(x)) with some other software, and then plotting those in TikZ or pgf? – Ivica Smolić Jan 20 '15 at 21:48
  • 1
    Well, the it would be nice to show your effort, or to be more specific. This way it looks like you didn't search at all. And no, I don't think that the gamma function exists... – yo' Jan 20 '15 at 21:53
  • 3
    I'd try gnuplot. It has an implementation of the gamma function. – 1010011010 Jan 20 '15 at 22:36
  • 1
    Using essentially the same code I posted for plotting the zeta function, you can plot gamma. You need to import that function, though, as is done here. – DJP Jan 20 '15 at 22:42

There is an elegant way… with the pst-func package:



\psaxes[ticksize=2pt -2pt]{->}(0,0)(-4.8,-4.8)(4.8,4.8)[$ x $, -120][$ y $, -140]
\psset{linewidth = 0.6pt, linecolor = LightSteelBlue3}
\multido{\i=-4+1}{4}{\psline(\i, -5.8)(\i, 5.8)}

enter image description here

  • I suppose the implication is that GAMMA is a built-in function? neat! – Sean Allred Jan 21 '15 at 2:41
  • It's defined in the pst-math module, that called by pst-func. Also defined: GAMMALN. – Bernard Jan 21 '15 at 9:39
  • @Bernard: Absolutely great! I couldn't ask for more elegant solution. Thank you! – Ivica Smolić Jan 21 '15 at 9:41

The Gamma function is also built in Asymptote. Here is a reproduction of Bernard's graph with this program.

import graph;
real Xmin=-5, Xmax=5, Ymin=-5, Ymax=5;
// Graphs
for (real x = Xmin; x < 0; x=x+1) {draw(graph(gamma, x+0.001, x+0.999), red);};
draw(graph(gamma, 0.1, Xmax), red);
// Clipping (cut the parts beyond the borders)
clip((Xmin, Ymin) -- (Xmax, Ymin) -- (Xmax, Ymax) -- (Xmin, Ymax) -- cycle);
// Asymptotes (no pun here)
for (real x=Xmin; x<0; x=x+1) {draw((x, Ymin)--(x, Ymax), 0.8*white);};
// Axes
xaxis(xmin=Xmin, xmax=Xmax, Ticks(Step=1, OmitTick(0, Xmax)), arrow=Arrow);
yaxis(ymin=Ymin, ymax=Ymax, Ticks(Step=1, OmitTick(0, Ymin, Ymax)), arrow=Arrow);

Gamma function

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.