我想繪製兩個 beta 分佈來比較先驗分佈和後驗分佈,但似乎係數對於 LaTeX 來說太大了?如何在不改變功能的情況下修復它?它有一些錯誤,包括Dimension too large
和Number too big
。
\documentclass[10pt]{article}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\definecolor{qqccqq}{rgb}{0,0.8,0}
\definecolor{qqttcc}{rgb}{0,0.2,0.8}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=8.333333333333332cm,y=1.0cm]
\draw[->,color=black] (-0.1,0) -- (1.1,0);
\foreach \x in {,0.2,0.4,0.6,0.8,1}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt) node[below] {\footnotesize $\x$};
\draw[color=black] (1.04,0.04) node [anchor=south west] { $\theta$};
\draw[->,color=black] (0,-0.5) -- (0,5.5);
\foreach \y in {,1,2,3,4,5}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt) node[left] {\footnotesize $\y$};
\draw[color=black] (0pt,-10pt) node[right] {\footnotesize $0$};
\clip(-0.1,-0.5) rectangle (1.1,5.5);
\draw[dash pattern=on 1pt off 1pt,color=qqttcc, smooth,samples=100,domain=8.000000000003847E-7:0.9999990727280006] plot(\x,{3682570000*(1-(\x))^(10.67)*(\x)^(21.49)});
\draw[color=qqccqq, smooth,samples=100,domain=8.000000000003847E-7:0.9999990727280006] plot(\x,{2120.93*(1-(\x))^(2.67)*(\x)^(9.49)});
\draw (0.49,4.17) node[anchor=north west] {$g(\theta|D)$};
\draw (0.89,3.23) node[anchor=north west] {$g(\theta)$};
\end{tikzpicture}
\end{document}
答案1
也可以考慮漸近線選項,因為它在圖形繪製中非常強大,特別是當存在曲線數組時。下面的範例將函數組織在數組中;其他屬性(如顏色、寬度、標籤等)也可以組織在陣列中,並在一個循環中繪製。此外,y
標籤的 - 座標被計算為曲線上的點。
asy-plot.tex
\documentclass{standalone}
\usepackage{lmodern}
\usepackage[inline]{asymptote}
\begin{document}
\begin{asy}
import graph;
size(250,170,IgnoreAspect);
real xMin=8.000000000003847e-7;
real xMax=0.9999990727280006;
int n=100;
typedef real Func(real x);
Func[] f={
new real(real x){return 3682570000*(1-x)^(10.67)*x^(21.49);},
new real(real x){return 2120.93*(1-x)^2.67*x^9.49;},
};
pen dashed=linetype(new real[] {4,3}); // set up dashed pattern
pen[] curvePen={rgb(0,0.8,0)+dashed,rgb(0,0.2,0.8),};
real[] curveWidth={1.6pt,2pt};
Label[] lab={
Label("$g(\theta\,\vert D)$",(0.6,f[0](0.6))),
Label("$g(\theta)$",(0.9,f[1](0.9))),
};
for(int i=0;i<f.length;++i){
draw(graph(f[i], xMin ,xMax ,n),curvePen[i]+curveWidth[i]);
label(lab[i],UnFill(2pt));
}
xaxis("",0,1.049,RightTicks(Step=0.1,step=0.05),EndArrow);
yaxis("",0,5-0.15,LeftTicks(Step=1,step=0.5),EndArrow);
\end{asy}
\end{document}
要處理它latexmk
,請建立文件latexmkrc
:
sub asy {return system("asy '$_[0]'");}
add_cus_dep("asy","eps",0,"asy");
add_cus_dep("asy","pdf",0,"asy");
add_cus_dep("asy","tex",0,"asy");
並運行latexmk -pdf asy-plot.tex
。結果看起來像
答案2
不是直接答案,但我會用pgfplots
它。也許在正確的位置打開fpu
庫,可能會解決問題,但您不需要繪製任何軸等,所以我認為這更方便。
\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{arrows}
\definecolor{qqccqq}{rgb}{0,0.8,0}
\definecolor{qqttcc}{rgb}{0,0.2,0.8}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round]
\begin{axis}[
axis lines=middle,
every inner x axis line/.append style={-triangle 45},
every inner y axis line/.append style={-triangle 45},
enlargelimits]
\addplot[dash pattern=on 1pt off 1pt,color=qqttcc, smooth,samples=100,domain=8.000000000003847E-7:0.9999990727280006] plot(\x,{3682570000*(1-(\x))^(10.67)*(\x)^(21.49)});
\addplot[color=qqccqq, smooth,samples=100,domain=8.000000000003847E-7:0.9999990727280006] plot(\x,{2120.93*(1-(\x))^(2.67)*(\x)^(9.49)});
\node at (axis cs:0.49,4.17) {$g(\theta|D)$};
\node at (axis cs:0.89,3.23) {$g(\theta)$};
\end{axis}
\end{tikzpicture}
\end{document}
與您的編輯相關的問題是,接近域末尾的數字變得太小。為了顯示我已經切換到 y 軸上的對數軸。 TeX 無法處理該精度,但fpu
TikZ 庫或pgfplots
預設可以在一定程度上處理並以除零錯誤退出。否則pgfplots
允許gnuplot
指令在 TeX 之外執行。請檢查手冊pgfplots
,您也不需要定義您使用的每種顏色。 xcolor 是一個非常強大的軟體包,因此您可以使用顏色混合功能。這是一個沒有任何軸設置等的最小範例,以展示如何易於使用:
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.8} % The latest version on CTAN
\begin{document}
\begin{tikzpicture}
\begin{semilogyaxis}
\addplot[red,smooth,samples=100,domain=0.0:1.0] {(3.1415926535*sin(((x)*3.1415926535)*180/pi))/2};
\addplot[green!80!black, smooth,samples=100,domain=0.0:1.0] {(x)^1^2*(1-(x))^8*sin(((x)*3.1415926535)*180/pi)*1/(3.44*10^(-7))};
\addplot[blue!80!green, ultra thick,smooth,samples=100,domain=0.0:1.0] {2.718281828^((-((x)-0.58)^2)/(0.1^2*2))/(abs(0.1)*sqrt(3.1415926535*2))};
\end{semilogyaxis}
\end{tikzpicture}
\end{document}