3

How to set the origin of y axis to 1?

Minimal example:

\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}

EDIT:

ymin=1 will set the axis to 1, but the value below 1 won't be displayed! ymin=1000 hides all the values!

6
  • xmin=1? (Or rather xmin=1000 in this case.) Aug 17, 2015 at 14:01
  • @TorbjørnT. thanks for your comment. It seems that the y axis should be modified instead of the x one. Check my edit.
    – gsamaras
    Aug 17, 2015 at 14:05
  • Is this what you're after then? Set axis x line to other origin than 0 Edit: Taking from Jake's code, I guess y filter/.code={\pgfmathparse{#1-1}}, yticklabel={\pgfmathparse{\tick+1}\pgfmathprintnumber{\pgfmathresult}} does what you want. Aug 17, 2015 at 14:31
  • @TorbjørnT. I had seen this before posting and it seems too complex, I was expecting to find one or two commands that would do the trick. Or maybe, I just can't see how the link will work on my minimal example.
    – gsamaras
    Aug 17, 2015 at 14:34
  • @TorbjørnT. no I did not see the edit, but my question was answered, thank you for the help.
    – gsamaras
    Aug 17, 2015 at 14:39

1 Answer 1

4

Is this what you want?

% 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}

enter image description here

2
  • Yes, thank you very much. Regarding this line of code though, \pgfplotsset{compat=1.9} % update to 1.12 if possible!, I had the editor in the latest version and I tried to update some other packages, but I still fail to be able to use 1.12. I am at Ubuntu, do you know any way to do this?
    – gsamaras
    Aug 17, 2015 at 14:42
  • @gsamaras not important here. It works. If you want to update, see here: tex.stackexchange.com/a/55459
    – LaRiFaRi
    Aug 17, 2015 at 16:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .