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.

Is it possible to define in pgfplots that y should correspond to Y cm in my plot?

I know how to do this in tkz-fct, so let me add an tkz-fct example to make more clear what I want:

\documentclass{article}

\usepackage{pgfplots}
\usepackage{tkz-fct}
\usetkzobj{all}

\begin{document}

\begin{tikzpicture}[scale=.5]
\tkzInit[xmax=10,ystep=3,ymax=10]
\tkzAxeXY
\tkzGrid
\tkzFct[color=red, thick,domain=0:10]{\x}
\tkzFct[domain=0:10]{\x**2}
\end{tikzpicture}
\begin{tikzpicture}[scale=.5]
\tkzInit[xmax=10,ystep=1.5,ymax=10]
\tkzAxeXY
\tkzGrid
\tkzFct[color=red, thick,domain=0:10]{\x}
\tkzFct[domain=0:10]{\x**2}
\end{tikzpicture}  
\end{document}

tikz-fct

In one case 3 corresponds to 0.5 cm on the y-axis in the picture, in the other case 1.5 corresponds to 0.5 cm on the y axis. This is achieved by using the scale=0.5 option together with the ystep option.

Not that it is important for me to have grids as in the tkz-fct example.

share|improve this question
    
Does how to maintain the ratio between two axis in pgfplots answer your question? –  Peter Grill Jan 2 '12 at 22:35

1 Answer 1

up vote 6 down vote accepted

You can specify the length of the unit vectors using the keys x and y. In this case, you would use x=0.5cm, y=0.5cm/3 for the first plot and x=0.5cm, y=0.5cm/1.5.

\documentclass{article}

\usepackage{pgfplots}

\begin{document}


\begin{tikzpicture}
\begin{axis}[
    samples=60,
    domain=0:10, xmax=10.5,
    restrict y to domain=0:10,
    axis lines=left,
    y=0.5cm/3,
    x=0.5cm,
    grid=both,
    xtick={0,...,10},
    ytick={0,3,...,9},
    compat=newest,
    xlabel=$x$, xlabel style={at={(1,0)}, anchor=west},
    ylabel=$y$, ylabel style={rotate=-90,at={(0,1)}, anchor=south}
]
\addplot [red] {x};
\addplot [black] {x^2};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[
    samples=60,
    domain=0:10, xmax=10.5,
    restrict y to domain=0:10,
    axis lines=left,
    y=0.5cm/1.5,
    x=0.5cm,
    grid=both,
    xtick={0,...,10},
    ytick={0,1.5,3,...,9},
    compat=newest,
    xlabel=$x$, xlabel style={at={(1,0)}, anchor=west},
    ylabel=$y$, ylabel style={rotate=-90,at={(0,1)}, anchor=south}
]
\addplot [red] {x};
\addplot [black] {x^2};
\end{axis}
\end{tikzpicture}
\end{document}
share|improve this answer

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.