Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am looking to expand the y- and x-axis values beyond the data for visual reasons. I tried to force the ticks and labels, but it did not work. I wish the two axis to start at zero and end beyond the maximum datapoints. This is my first attempt at pgfplots.

\documentclass{article}
\usepackage{tikz,pgfplots}
\usetikzlibrary{snakes,backgrounds,arrows,decorations.markings}
\begin{document}
%
%
\begin{center}
\begin{tikzpicture}
                \begin{axis}[
                        small, 
                        xlabel=Time in min.,
                        ylabel=Distance in mi.,
                        axis y line=left,
                        axis x line=bottom,
                        xtick={0,2,4,6,8,10,12},
                        ytick={0,1,1.5,2,...,3.5},
                        xticklabels={0,2,4,6,8,10,12},
                        yticklabels={0,1,1.5,2,...,3.5},
                        xtickmin=0,
                        xtickmax=11,
                        ytickmin=0,
                        ytickmax=3.5
                            ] 
                \addplot[color=blue,mark=*] 
                    coordinates {
                        (1,1)
                        (2,1)
                        (5,3)
                        (8,3)
                        (9,2)
                        (10,3)
                                };
                \end{axis} 
\end{tikzpicture}
\end{center}
%
%
\end{document}
share|improve this question

1 Answer 1

up vote 3 down vote accepted

The visible range of the plot can be specified using xmin, xmax, ymin, etc. If you want to automatically extend the axis ranges beyond the largest values, you can set enlargelimits=upper (this behaviour can be controlled quite precisely: You can enlarge the axis by a certain number of units, by a certain percentage, or by a certain length. Check the manual for details).

In your example, you can simply say xmin=0, ymin=0, enlargelimits=upper, without the need to specify the ticks yourself:

\documentclass{article}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
                \begin{axis}[
                        small, 
                        compat=1.8,
                        xlabel=Time in min.,
                        ylabel=Distance in mi.,
                        axis y line=left,
                        axis x line=bottom,
                        xmin=0,
                        ymin=0,
                        enlargelimits=upper
                            ] 
                \addplot[color=blue,mark=*] 
                    coordinates {
                        (1,1)
                        (2,1)
                        (5,3)
                        (8,3)
                        (9,2)
                        (10,3)
                                };
                \end{axis} 
\end{tikzpicture}
\end{document}
share|improve this answer
    
Couldn't find that in the manual. Thanks –  Calhistorian Jun 4 '13 at 18:09

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.