1

I need to draw two pdf curves with known shape parameters for a beamer presentation. I really appreciate if I can get some advise on that.

enter image description here

Reza
  • 811
  • Welcome to TeX.SX! Please help us (and also you) and add a minimal working example (MWE), that illustrates your problem. Reproducing the problem and finding out what the issue is will be much easier when we see compilable code, starting with \documentclass and ending with \end{document}. – Bobyandbob May 04 '17 at 16:24
  • Related: www.texample.net/tikz/examples/tag/plots/ or https://tex.stackexchange.com/a/341886/124842 – Bobyandbob May 04 '17 at 16:26

2 Answers2

4

As was already suggested by Bobyandbob in the comment below the question you can adopt my answer given here to get what you need.

To summarize what is given there:
If you have installed gnuplot you can use PGFPlots raw gnuplot function to define the functions needed for the beta function, then plotting a data file which is read by PGFPlots and used for the plot.

% used PGFPlots v1.14
\documentclass[border=5pt]{standalone}
\usepackage{pgfplots}
    % define a command which stores all commands that are needed for every
    % `raw gnuplot' call
    \newcommand*\GnuplotDefs{
        % set number of samples
        set samples 51;
        %
        % define beta distribution function
        % (copied from <http://gnuplot.sourceforge.net/demo/prob.5.gnu>)
        Binv(p,q)=exp(lgamma(p+q)-lgamma(p)-lgamma(q));
        beta(x,p,q)=p<=0||q<=0?1/0:x<0||x>1?0.0:Binv(p,q)*x**(p-1.0)*(1.0-x)**(q-1.0);
    }
\begin{document}
\begin{tikzpicture}
        % define macros which are needed for the axis limits as well as for
        % setting the domain of calculation
        \pgfmathsetmacro{\xmin}{0}
        \pgfmathsetmacro{\xmax}{1}
    \begin{axis}[
        xmin=\xmin,
        xmax=\xmax,
        no markers,
    ]
        \addplot gnuplot [raw gnuplot] {
            % first call all the "common" definitions
            \GnuplotDefs
            % and then create the data tables
            % in GnuPlot `x` key is identical to PGFPlots `domain` key
            %
            % "plot" beta function
            plot [x=\xmin:\xmax] beta(x,1,1);
        };
        \addplot gnuplot [raw gnuplot] {
            \GnuplotDefs
            plot [x=\xmin:\xmax] beta(x,7,5);
        };
    \end{axis}
\end{tikzpicture}
\end{document}

image showing the result of above code

Stefan Pinnow
  • 29,535
2

A short code with pstricks and its module pst-func, which defines a \psBetaDist command (to be compiled with pdflatex with the --enable-write18 switch (MiKTeX) or -shell-escape (TeX Live, MacTeX):

\documentclass[x11names, border=1pt]{standalone}

\usepackage{pst-func, pst-plot}
\usepackage{auto-pst-pdf}

\begin{document}

\psset{xunit=8cm, yunit=2cm}
\begin{pspicture*}(-1,-1)(1.1,3.1)
\psaxes[linecolor=LightSteelBlue3, tickcolor=LightSteelBlue3, ticksize=3pt -3pt, ticks=all, tickstyle=bottom, Dx=0.1, Dy=0.5, labelFontSize=\scriptstyle]{-}(0,0)(1.005,3.005)
\psBetaDist[linecolor=DarkGoldenrod1, alpha=1, beta=1]{0.005}{0.995}
\psBetaDist[linecolor=OliveDrab4, alpha=7, beta=5]{0.005}{0.995}
\end{pspicture*}

\end{document} 

enter image description here

Bernard
  • 271,350
  • This figure looks great. I am using online sharelatex. Apparently it is not able to compile codes with pstricks. – Reza May 08 '17 at 01:41
  • Probably it doesn't allow escaping (for security reasons). If you can compile with xelatex, it can also compile (remove the loading of auto-pst-pdf). Otherwise there's the traditional way: latex -> dvips -> pstopdf. – Bernard May 08 '17 at 01:45