\addplot 绘图功能不起作用

\addplot 绘图功能不起作用

我想用 Tikz 绘制一个函数。我是这样做的:

\documentclass[11pt]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[german]{babel}
\usepackage{mathtools} 
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{tikz}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\pgfplotsset{compat=1.11}

\begin{document}
\begin{figure}
\begin{tikzpicture}[scale=10]
\draw (0,0) -- coordinate (x axis mid) (1,0);
\draw (0,0) -- coordinate (y axis mid) (0,0.59);

\foreach \x in {0.0,0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1}
        \draw (\x,0.1pt) -- (\x,-0.3pt)
        node[anchor=north] {\x};
\foreach \x in {0.05,0.15,0.25,0.35,0.45,0.55,0.65,0.75,0.85,0.95}
        \draw (\x,0.07pt) -- (\x,-0.2pt)
        node[anchor=north] {};
\foreach \y in {0.0,0.1,0.2,0.3,0.4,0.5}
        \draw (0.1pt,\y) -- (-0.3pt,\y)
                    node[anchor=east] {\y};
\foreach \y in {0.05,0.15,0.25,0.35,0.45,0.55}
        \draw (0.07pt,\y) -- (-0.2pt,\y)
        node[anchor=east] {};
\addplot [] {$\frac{1+ \frac{x}{1-x}}{\sqrt{2*\pi}*\sqrt{{\frac{x}{1-x}}^{2} + 1}}$};                       
\draw [-] (0,0.4) -- (1,0.4);
\end{tikzpicture}
\end{figure}
\end{document}

不幸的是,LaTeX 无法编译,并指出这 \addplot [] {$\frac{1+ \frac{x}{1-x}}{\sqrt{2*\pi}*\sqrt{{\frac{x}{1-x}}^{2} + 1}}$}; 是一个未定义的控制序列。您知道如何绘制此函数吗?

非常感谢!并致以最诚挚的问候!

答案1

我建议您实际使用 PGFPlots,因为您已经将其包括在内。您是否正在尝试做这样的事情?

\documentclass[tikz]{standalone}

    \usepackage{pgfplots}
    %why are you not using at least compat=1.3?
    \pgfplotsset{compat=1.11}

\begin{document}

    \begin{tikzpicture}[scale=10]
        \begin{axis}[
            xmin=0,
            xmax=1,
            ymin=0,
            ymax=0.6,
            xtick={0,0.1,...,1.1},
            minor xtick={0.05,0.15,...,0.95},
            ytick={0,0.1,...,0.6},
            minor ytick={0.05,0.15,...,0.55},
            ]
            \addplot[domain=0:1,samples=50] {(1+(x/(1-x)))/(sqrt(2*pi)*sqrt((x/(1-x))^2 +1))};
            \addplot[] plot coordinates{(0,0.4) (1,0.4)};
        \end{axis}
    \end{tikzpicture}

\end{document}

由此产生了如下结果: 情节表达

如果需要的话,可以轻松更改刻度等。

相关内容