将 y 轴原点设为 1

将 y 轴原点设为 1

如何将 y 轴的原点设置为 1?

最小示例:

\documentclass{article} 
\usepackage{pgfplots}
\pgfplotsset{compat=1.9}
\begin{document}

\begin{figure}    
\centering
\begin{tikzpicture}
       \begin{axis}[%
            ,xlabel=$N$
            ,ylabel=speedup
            ,axis x line=bottom
            ,axis y line=left
            ,scaled x ticks=base 10:-3
            ]
            \addplot[very thick] coordinates {(755,1.4) (1978, 1.6) (6273, 1.8) (12222, 2.1)};
            \addplot[very thick, color=blue] coordinates {(6273, 0.2) (12222, 1.2)};
        \end{axis}
\end{tikzpicture}
\caption{Speedup of distributed execution, versus serial. N is the leading dimension of the matrix. The black plot is for the case of one computer, while the blue one is for two computers.}
\label{plot:speedup}
\end{figure}

As we see in figure \ref{plot:speedup} ...

\end{document}

编辑:

ymin=1将把轴设置为 1,但低于 1 的值将不会显示!ymin=1000隐藏所有值!

答案1

你想要什么?

% arara: pdflatex
% arara: pdflatex

\documentclass{article} 
\usepackage{pgfplots}
\pgfplotsset{compat=1.9} % update to 1.12 if possible!
\pgfplotsset{%
    axis line origin/.style args={#1,#2}{
        x filter/.append code={ % Check for empty or filtered out numbers
            \ifx\pgfmathresult\empty\else\pgfmathparse{\pgfmathresult-#1}\fi
        },
        y filter/.append code={
            \ifx\pgfmathresult\empty\else\pgfmathparse{\pgfmathresult-#2}\fi
        },
        xticklabel=\pgfmathparse{\tick+#1}\pgfmathprintnumber{\pgfmathresult},
        yticklabel=\pgfmathparse{\tick+#2}\pgfmathprintnumber{\pgfmathresult}
    }
}

\begin{document}    
    \begin{figure}    
        \centering
        \begin{tikzpicture}
        \begin{axis}[%
        ,xlabel=$N$
        ,xmax=13000
        ,ylabel=speedup
        ,axis x line=middle
        ,axis y line=left
        ,axis line origin={0,1}
        ,scaled x ticks=base 10:-3
        ]
        \addplot[very thick] coordinates {(755,1.4) (1978, 1.6) (6273, 1.8) (12222, 2.1)};
        \addplot[very thick, color=blue] coordinates {(6273, 0.2) (12222, 1.2)};
        \end{axis}
        \end{tikzpicture}
        \caption[Speedup of distributed execution, versus serial]{Speedup of distributed execution, versus serial. N is the leading dimension of the matrix. The black plot is for the case of one computer, while the blue one is for two computers.}
        \label{plot:speedup}
    \end{figure}

    As we see in figure \ref{plot:speedup} ...  
\end{document}

在此处输入图片描述

相关内容