2

I have the following code, which produces no errors in the log files:

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{width=14cm,compat=1.14, label style={font=\huge}, tick label style={font=\huge}}
\usepgfplotslibrary{fillbetween}
\begin{document}

\pgfmathdeclarefunction{lgamma}{1}{%
    \pgfmathparse{ln(2.506628274631*sqrt(1/#1) + 0.20888568*(1/#1)^(1.5) + 0.00870357*(1/#1)^2.5 - (174.2106599*(1/#1)^3.5)/25920 - (715.6423511*(1/#1)^4.5)/1244160)*(-ln(1/#1)-1)*#1}
    }

\pgfmathdeclarefunction{chisq}{1}{%
  \pgfmathparse{exp((0.5*#1-1.0)*ln(x)-0.5*x-lgamma(0.5*#1)-#1*0.5*0.693147180559945)}%
}

\begin{tikzpicture}

\begin{axis}[
  no markers, domain=0.01:3.5, samples=300,
  axis x line=bottom, axis y line=left,
  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},
  height=5cm, width=14cm,
  xtick={0.01, 3.5}, ytick=\empty,
  enlargelimits=false, clip=false, axis on top,
  xticklabels={0, $\infty$}, %  so do it manually instead
  ]

  \addplot [very thick,red, name path=f] {chisq(1)};
 % \path[name path=axis](axis cs:0.01,0) -- (axis cs:3.5,0);
  %\addplot[thick, color=red, fill=red, fill opacity=0.5] fill between [of=f and axis, soft clip={domain=0.01:3.5},];
  
\end{axis}

\end{tikzpicture}
\end{document}

However, it produces a blank page when I try to use pdflatex. Why? How can I get my chisq(1) plot to show, and the area between f(x) and the x-axis to be shaded in red?

0

enter image description here

\documentclass[border=5mm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.17,
             width=14cm, height=5cm,
             label style={font=\huge}, 
             tick label style={font=\huge}}
\usepgfplotslibrary{fillbetween}
\usetikzlibrary{arrows.meta}

\begin{document}
\pgfmathdeclarefunction{lgamma}{1}{%
    \pgfmathparse{ln(2.506628274631*sqrt(1/#1) + 0.20888568*(1/#1)^(1.5) + 0.00870357*(1/#1)^2.5 - (174.2106599*(1/#1)^3.5)/25920 - (715.6423511*(1/#1)^4.5)/1244160)*(-ln(1/#1)-1)*#1}
    }

\pgfmathdeclarefunction{chisq}{1}{%
  \pgfmathparse{exp((0.5*#1-1.0)*ln(x)-0.5*x-lgamma(0.5*#1)-#1*0.5*0.693147180559945)}%
}

    \begin{tikzpicture}
\begin{axis}[
     axis lines=middle,
     axis line style= {-Straight Barb},
     axis on top,
  ytick=\empty,
  xtick=\empty,
%
  extra x ticks={0.01, 3.5},
  extra x tick labels={$0$, $\infty$}, % so do it manually instead
  no markers,
  domain=0.01:3.5,
  samples=300,
            ]
\addplot[very thick,red, name path=f] {chisq(1)};
\path[name path=axis] (0,0) -- (3.5,0);
\addplot [red, fill opacity=0.5] fill between [of=f and axis];
\end{axis}
    \end{tikzpicture}
\end{document}
2
  • Thank you, but I get an error that says "Package pgfplots Error: Sorry, 'compat=1.17' is unknown in his context. Please use at most 'compat=1.14'. I think this might be because my TeX distribution is out of date? Using compat=1.14 produces the red part, but not the axes or the labels (0, inf). – StatsSorceress Dec 30 '20 at 17:25
  • 2
    it seems that you have old version (1.14) of pgpfplots package. Please upgrade it tpo 1.17 or in MWE change comapt=1.17 to comapt=1.14. I tested MWE with version 1.17. – Zarko Dec 30 '20 at 18:00

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.