5

enter image description hereI'm trying to plot the following graph in tikzpicture:

enter image description here

However, I have a hard time defining the function properly, as my MWE currently is this:

\documentclass[12pt]{article}
\usepackage{pgfplots}

\begin{document}
\begin{tikzpicture}[
    declare function={
            gamma(\x)= 0.25*\x*\x*exp(-0.5*\x);
    }
]

\begin{axis}[
  no markers, domain=0:13, samples=200,
  axis lines*=left, xlabel=$\tau$, ylabel=$V(\tau)$,
  every axis y label/.style={at=(current axis.above origin),anchor=south},
  every axis x label/.style={at=(current axis.right of origin),anchor=west},
  xtick={4}, 
  xticklabel={$\tau^{\ast}$},
  ytick=\empty,
  enlargelimits=false, clip=false, axis on top,
  %grid = major,    
  xmin=0, ymin=0,
]
\addplot [very thick,cyan] {gamma(x)}; 
\end{axis}
\end{tikzpicture}

\end{document}

Any help would be appreciated! Many thanks!

  • 1
    Remove the clip=false and ymin=0 options, and plot {-gamma(x)} instead of {gamma(x)}, and you should get the correct result. – Jake Jan 30 '16 at 20:07
4

This code and result is mainly from Jake's comment (no CW answer as no wiki intended and possible points I could then put via bounty to Jake's great answers)

  • remove clip=false
  • remove ymin=0
  • plot the negative function: \addplot [very thick,cyan] {-gamma(x)};

And then, for a top x axis

  • add axis x line = top as axis option

So, you will get:

Output Gamma function

Full code:

\documentclass[border=10pt]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[
    declare function={
            gamma(\x)= 0.25*\x*\x*exp(-0.5*\x);
    }
]
\begin{axis}[
  no markers, domain=0:13, samples=200,
  axis lines*=left, xlabel=$\tau$, ylabel=$V(\tau)$,
  every axis y label/.style={at=(current axis.above origin),anchor=south},
  every axis x label/.style={at=(current axis.right of origin),anchor=west},
  xtick={4}, 
  xticklabel={$\tau^{\ast}$},
  ytick=\empty,
  enlargelimits=false,
  axis x line = top,
  xmin=0,
]
\addplot [very thick,cyan] {-gamma(x)}; 
\end{axis}
\end{tikzpicture}
\end{document}

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.