我对这两者都不熟悉GeoGebra
,TikZ
所以我的问题可能有点愚蠢。
我曾经GeoGebra
画过柯西分布的分布函数,即
F(x) = 1/\pi \arctan(10(x-0.5))+0.5
。
这是我做的情节GeoGebra
这是 GeoGebra 生成的 TikZ 代码
或者
\documentclass[10pt]{article}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\draw[->,color=black] (-0.6,0.) -- (1.6,0.);
\foreach \x in {-0.4,-0.2,0.2,0.4,0.6,0.8,1.,1.2,1.4,1.6}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt);
\draw[->,color=black] (0.,-0.6) -- (0.,1.2);
\foreach \y in {-0.5,-0.4,-0.3,-0.2,-0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.,1.1}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt);
\clip(-0.6,-0.1) rectangle (1.6,1.2);
\draw[smooth,samples=100,domain=-0.6:1.6] plot(\x,{1.0/3.1415926535* rad(atan(10.0*((\x)-0.5)))+0.5});
\draw [dash pattern=on 1pt off 1pt,domain=-0.6:1.6] plot(\x,{(-1.-0.*\x)/-1.});
\draw [->,dash pattern=on 1pt off 1pt] (0.,0.688120318294) -- (0.568235782686,0.690599882462);
\draw [->,dash pattern=on 1pt off 1pt] (0.568235782686,0.690599882462) -- (0.57,0.);
\draw (-0.10792616721,1.20729312763) node[anchor=north west] {$F(x)$};
\draw (-0.0673181324647,0.722300140252) node[anchor=north west] {$U$};
\draw (0.534636264929,0.0039270687237) node[anchor=north west] {$X$};
\draw (1.47339847991,0.0112201963534) node[anchor=north west] {$x$};
\draw (-0.0553745928339,1.01767180926) node[anchor=north west] {$1$};
\end{tikzpicture}
\end{document}
笔记。rad
我在前面添加了函数atan
,因为 TikZ 使用度数而不是弧度;请参阅这里的讨论
最后,这是我在 LaTex 中编译代码后得到的图
有什么问题?我遗漏了什么吗?
答案1
(注:我刚刚注意到 Harish Kumar 之前在评论中提到过我的解决方案)
环境tikzpicture
具有允许您控制比例的选项(例如相对于文本大小)。看起来 GeoGebra 生成的代码错误计算了这个比例,甚至对于放置标签的位置也是如此。
我通过指定这些选项解决了这个问题x=10.0cm,y=10.0cm
,如下所示。现在的结果看起来几乎等于您的 GeoGebra 窗口屏幕截图。
\documentclass[10pt]{article}
\usepackage{pgf,tikz}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\scalebox{0.5}{
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=10.0cm,y=10.0cm]
\draw[->,color=black] (-0.6,0.) -- (1.6,0.);
\foreach \x in `{-0.4,-0.2,0.2,0.4,0.6,0.8,1.,1.2,1.4,1.6}
\draw[shift={(\x,0)},color=black] (0pt,2pt) -- (0pt,-2pt);
\draw[->,color=black] (0.,-0.6) -- (0.,1.2);
\foreach \y in {-0.5,-0.4,-0.3,-0.2,-0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1.,1.1}
\draw[shift={(0,\y)},color=black] (2pt,0pt) -- (-2pt,0pt);
\clip(-0.6,-0.1) rectangle (1.6,1.2);
\draw[smooth,samples=100,domain=-0.6:1.6] plot(\x,{1.0/3.1415926535* rad(atan(10.0*((\x)-0.5)))+0.5});
\draw [dash pattern=on 1pt off 1pt,domain=-0.6:1.6] plot(\x,{(-1.-0.*\x)/-1.});
\draw [->,dash pattern=on 1pt off 1pt] (0.,0.688120318294) -- (0.568235782686,0.690599882462);
\draw [->,dash pattern=on 1pt off 1pt] (0.568235782686,0.690599882462) -- (0.57,0.);
\draw (-0.10792616721,1.20729312763) node[anchor=north west] {$F(x)$};
\draw (-0.0673181324647,0.722300140252) node[anchor=north west] {$U$};
\draw (0.534636264929,0.0039270687237) node[anchor=north west] {$X$};
\draw (1.47339847991,0.0112201963534) node[anchor=north west] {$x$};
\draw (-0.055374592`8339,1.01767180926) node[anchor=north west] {$1$};
\end{tikzpicture}
}
\end{document}
答案2
使用pgfplots
,这项工作相当简单:
代码:
\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines=middle,
samples=200,
xtick=\empty,
ytick=\empty,
width=.8\linewidth,
domain=-3:3
]
\addplot+[no marks,blue] {1/pi*atan(10*(x-0.5))+0.5};
\node[circle,fill,inner sep=1.5pt]
(aux) at (axis cs:0.75,{1/pi*atan(10*(0.75-0.5))+0.5}) {};
\draw[dotted,->]
(axis cs:0.75,0) node[below] {$x$} -- (aux);
\draw[dotted,->]
(axis cs:0,{1/pi*atan(10*(0.75-0.5))+0.5}) node[left] {$v$} -- (aux);
\end{axis}
\end{tikzpicture}
\end{document}
将 0.75(我仅将其用于示例)更改为所需值以定位路径上的点。