绘制掷骰子的 PMF 和 CDF

绘制掷骰子的 PMF 和 CDF

... 投掷骰子,每个数字的概率为 1/6。

我的概率质量函数代码是

\documentclass[pstricks, margin=2mm]{standalone}
\usepackage{pst-all}

\begin{document}
    \definecolor{col}{RGB}{125, 185, 250}
\savedata{\data}[
1 0.1667
2 0.1667
3 0.1667
4 0.1667
5 0.1667
6 0.1667]

\psset{xunit=0.6cm,yunit=10cm}
\pspicture(-3,-0.1)(12,0.5)
\rput(0,0){
\listplot[
origin={-1,0},
plotstyle=LineToXAxis,
linecolor=col,
]{\data}
\psaxes[Ox=1,yAxis=false,Dx=1,dx=1,tickstyle=bottom]{-}(0,0)(5,0.4)\uput[0](2.25,-0.09){$x$}
\rput(-0.25cm,0.25cm){\psaxes[xAxis=false,Dy=0.05,dy=0.10,Oy=0.05,tickstyle=bottom]{->}(0,0.45)}\uput[-90]{90}(-2.5,0.4){$f(X)=P(X=x)$}
}
\endpspicture
\end{document}

得出以下数字:

阴谋

第一个问题是 y 轴上的表示偏离了大约 0.1...我猜这与定义有关yAxis,但我可以弄清楚。

第二个问题是如何获得具有相同骰子分布的 CDF pstricks(我已经看到了可以适应的代码tikz,但我想在上进行调整pstricks)。

谢谢你的帮助。

答案1

使用不同的yunit

 \listplot[origin={-1,0},yunit=1.667,
       plotstyle=LineToXAxis,linecolor=col,]{\data}

在此处输入图片描述

答案2

\documentclass[margin=2mm]{standalone}
\usepackage{pst-all}

\begin{document}
    \definecolor{col}{RGB}{125, 185, 250}
    \savedata{\data}[
    1 0.1667
    2 0.1667
    3 0.1667
    4 0.1667
    5 0.1667
    6 0.1667]
    \psset{xunit=1cm,yunit=5cm}
    \pspicture(-2,-0.2)(6,1.1)
        \listplot[yunit=1.667,
        origin={-1,0}, 
        plotstyle=LineToXAxis,
        linecolor=col,
        linewidth=2pt
        ]{\data}
        \psaxes[Ox=1,yAxis=false,Dx=1,dx=1,tickstyle=bottom]{-}(0,0)(5,0.4)\uput[0](2.25,-0.2){$x$}
        \rput(-0.2cm,0.2cm){\psaxes[xAxis=false,Dy=0.05,dy=0.1,Oy=0.05,tickstyle=bottom]{->}(0,0.5)}\uput[-90]{90}(-1.5,0.55){$f(X)=\text{P}[X=x]$}
    \endpspicture
    %
    \pspicture(-2,-0.2)(7,1.1)
        {\psset{linecolor=col, linewidth=1.5pt,dotsize=0.2}%
        \psline{-o}(0,0.04)(1,0.04)
        \multido{\ia=1+1,\ib=2+1,\ra=0.16667+0.16667}{6}{%
          \psline{*-o}(\ia,\ra)(\ib,\ra)}       
        \psline{*-}(6,1)(6.5,1)}
        \psaxes[Ox=0,yAxis=false,Dx=1,dx=1,tickstyle=bottom]{-}(0,0)(6,0.4)
        \uput[0](2.25,-0.2){$x$}
        \rput(-0.2cm,0.2cm){%
            \psaxes[xAxis=false,Dy=0.10,dy=0.1,Oy=0.0,tickstyle=bottom]{-}(0,1.001)
            \uput[-90]{90}(-1.5,0.9){$f(X)=\text{P}[X\le x]$}
        }
    \endpspicture
\end{document}

在此处输入图片描述

答案3

这可能不是最明智的做法,但是......

\documentclass[pstricks, margin=2mm]{standalone}
\usepackage{pst-all}
\usepackage{graphicx}

\begin{document}
    \definecolor{col}{RGB}{125, 185, 250}
\savedata{\data}[
1 0.1667
2 0.1667
3 0.1667
4 0.1667
5 0.1667
6 0.1667]
\psset{xunit=1cm,yunit=5cm}
\pspicture(-3,-0.2)(12.5,1.1)
\rput(-1.3,0){
\listplot[yunit=1.667,
origin={-1,0}, 
plotstyle=LineToXAxis,
linecolor=col,
linewidth=2pt
]{\data}
\psaxes[Ox=1,yAxis=false,Dx=1,dx=1,tickstyle=bottom]{-}(0,0)(5,0.4)\uput[0](2.25,-0.2){$x$}
\rput(-0.2cm,0.2cm){\psaxes[xAxis=false,Dy=0.05,dy=0.1,Oy=0.05,tickstyle=bottom]{->}(0,0.5)}\uput[-90]{90}(-1.5,0.55){$f(X)=\text{P}[X=x]$}
}
\rput(6.1,0){
\psline[yunit=1,linecolor=col, linewidth=1.5pt,dotsize=0.2]{-o}(0,0.04)(1,0.04)
\psline[yunit=1.1,linecolor=col, linewidth=1.5pt,dotsize=0.2]{*-o}(1,0.1666)(2,0.1666)
\psline[yunit=1.01,linecolor=col, linewidth=1.5pt,dotsize=0.2]{*-o}(2,0.3333)(3,0.333)
\psline[yunit=1.,linecolor=col, linewidth=1.5pt,dotsize=0.2]{*-o}(3,0.5)(4,0.5)
\psline[yunit=1.,linecolor=col, linewidth=1.5pt,dotsize=0.2]{*-o}(4,0.66667)(5,0.66667)
\psline[yunit=1.,linecolor=col, linewidth=1.5pt,dotsize=0.2]{*-o}(5,0.8333)(6,0.8333)
\psline[yunit=1.,linecolor=col, linewidth=1.5pt,dotsize=0.2]{*-}(6,1)(6.5,1)


\psaxes[Ox=0,yAxis=false,Dx=1,dx=1,tickstyle=bottom]{-}(0,0)(6,0.4)\uput[0](2.25,-0.2){$x$}
\rput(-0.2cm,0.2cm){
\psaxes[xAxis=false,Dy=0.10,dy=0.1,Oy=0.0,tickstyle=bottom]{-}(0,1.001)\uput[-90]{90}(-1.5,0.9){$f(X)=\text{P}[X\le x]$}
}

\rput[lb](-8,0.85){\includegraphics[scale=.5]{Dado.pdf}}

}
\endpspicture
\end{document}

在此处输入图片描述

相关内容