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.
Asked
Active
Viewed 1,949 times
1
2 Answers
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}
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}
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 ofauto-pst-pdf). Otherwise there's the traditional way:latex -> dvips -> pstopdf. – Bernard May 08 '17 at 01:45



\documentclassand ending with\end{document}. – Bobyandbob May 04 '17 at 16:24