使用 TikZ 生成的图表上的刻度标记/范围问题

使用 TikZ 生成的图表上的刻度标记/范围问题

我在让使用 TikZ 生成的图表上的刻度标记正确显示方面遇到了一些困难。代码如下,问题可以在第二张图 (b) 的垂直轴中看到。我该如何解决这个小问题?

\begin{figure}
    \centering
    \subfigure[hard limiter]{
        \begin{tikzpicture}[font=\scriptsize]
            \begin{axis}[
                xtick=\empty,
                ytick={-1, 0, 1},
                xlabel=${x}$,
                ylabel=${f_{h}\left(x\right)}$,
                width=150 pt]
                \addplot+[mark=none, black]
                    coordinates{
                        (-1, -1)
                        (0, -1)
                        (0, 1)
                        (1, 1)
                    };
            \end{axis}
        \end{tikzpicture}
        \label{figure:hard_limiter_1}
    }
    \\
    \subfigure[threshold logic]{
        \begin{tikzpicture}[font=\scriptsize]
            \begin{axis}[
                ymin=-1,
                xtick=\empty,
                ytick={-1, 0, 1},
                xlabel=${x}$,
                ylabel=${f_{t}\left(x\right)}$,
                width=150 pt]
                \addplot+[mark=none, black]
                    coordinates{
                        (-1, 0)
                        (0, 0)
                        (1, 1)
                    };
            \end{axis}
        \end{tikzpicture}
        \label{figure:threshold_logic_1}
    }
    \subfigure[sigmoid]{
        \begin{tikzpicture}[font=\scriptsize]
            \begin{axis}
                [
                    xtick=\empty,
                    ytick={-1, 0, 1},
                    xlabel=${x}$,
                    ylabel=${f_{s}\left(x\right)}$,
                    width=150 pt
                ]
                \addplot+[mark=none, smooth, black] {2/(1+e^(-x))-1};
            \end{axis}
        \end{tikzpicture}
        \label{figure:sigmoid_1}
    }
    \caption{three representative nonlinearities}
    \label{figure:three_representative_nonlinearities_1}
\end{figure}

答案1

一种可能性(我只是添加了一个 y 坐标等于 -1 的坐标):

\documentclass{article}
\usepackage{pgfplots}
\usepackage{subfigure}

\pgfplotsset{compat=1.8}

\begin{document}

\begin{figure}
    \centering
    \subfigure[hard limiter]{%
        \begin{tikzpicture}[font=\scriptsize]
            \begin{axis}[
                xtick=\empty,
                ytick={-1, 0, 1},
                xlabel=${x}$,
                ylabel=${f_{h}\left(x\right)}$,
                width=150 pt]
                \addplot+[mark=none, black]
                    coordinates{
                        (-1, -1)
                        (0, -1)
                        (0, 1)
                        (1, 1)
                    };
            \end{axis}
        \end{tikzpicture}%
        \label{figure:hard_limiter_1}%
    }%
    \\
    \subfigure[threshold logic]{%
        \begin{tikzpicture}[font=\scriptsize]
            \begin{axis}[
                xtick=\empty,
                ytick={-1, 0, 1},
                xlabel=${x}$,
                ylabel=${f_{t}\left(x\right)}$,
                width=150 pt]
                \addplot+[mark=none, black]
                    coordinates{
                        (-1, 0)
                        (0, 0)
                        (1, 1)
                    };
                \addplot+[mark=none] coordinates{(-1,-1)};
            \end{axis}
        \end{tikzpicture}%
        \label{figure:threshold_logic_1}%
    }\quad
    \subfigure[sigmoid]{%
        \begin{tikzpicture}[font=\scriptsize]
            \begin{axis}
                [
                    xtick=\empty,
                    ytick={-1, 0, 1},
                    xlabel=${x}$,
                    ylabel=${f_{s}\left(x\right)}$,
                    width=150 pt
                ]
                \addplot+[mark=none, smooth, black] {2/(1+e^(-x))-1};
            \end{axis}
        \end{tikzpicture}%
        \label{figure:sigmoid_1}%
    }
    \caption{three representative nonlinearities}
    \label{figure:three_representative_nonlinearities_1}
\end{figure}

\end{document}

在此处输入图片描述

我从你的代码中隐藏了一些虚假空格。

顺便说一句,subfigure这是一个过时的软件包,不应再使用。您可以使用subfig或者subcaption反而。

这是您的代码示例,使用subcaption

\documentclass{article}
\usepackage{pgfplots}
\usepackage{subcaption}

\pgfplotsset{compat=1.8}

\begin{document}

\begin{figure}
\begin{subfigure}{\linewidth}
\centering
\begin{tikzpicture}[font=\scriptsize]
            \begin{axis}[
                xtick=\empty,
                ytick={-1, 0, 1},
                xlabel=${x}$,
                ylabel=${f_{h}\left(x\right)}$,
                width=150 pt]
                \addplot+[mark=none, black]
                    coordinates{
                        (-1, -1)
                        (0, -1)
                        (0, 1)
                        (1, 1)
                    };
            \end{axis}
        \end{tikzpicture}
\caption{hard limiter}
\label{figure:hard_limiter_1}%
\end{subfigure}\\[1ex]
\begin{subfigure}{.5\linewidth}
\centering
        \begin{tikzpicture}[font=\scriptsize]
            \begin{axis}[
                xtick=\empty,
                ytick={-1, 0, 1},
                xlabel=${x}$,
                ylabel=${f_{t}\left(x\right)}$,
                width=150 pt]
                \addplot+[mark=none, black]
                    coordinates{
                        (-1, 0)
                        (0, 0)
                        (1, 1)
                    };
                \addplot+[mark=none] coordinates{(-1,-1)};
            \end{axis}
        \end{tikzpicture}
\caption{threshold logic}
\label{figure:threshold_logic_1}
\end{subfigure}%
\begin{subfigure}{.5\linewidth}
\centering
        \begin{tikzpicture}[font=\scriptsize]
            \begin{axis}
                [
                    xtick=\empty,
                    ytick={-1, 0, 1},
                    xlabel=${x}$,
                    ylabel=${f_{s}\left(x\right)}$,
                    width=150 pt
                ]
                \addplot+[mark=none, smooth, black] {2/(1+e^(-x))-1};
            \end{axis}
        \end{tikzpicture}
\caption{sigmoid}
\label{figure:sigmoid_1}
\end{subfigure}
\caption{three representative nonlinearities}
\label{figure:three_representative_nonlinearities_1}
\end{figure}

\end{document}

在此处输入图片描述

相关内容