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.

Here is an MWE for a contour plot.

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.7}

\begin{document}

\begin{tikzpicture}

    \begin{axis}[
        %   title = {$x \exp(-x^2-y^2)$}
        , xlabel = $x$
            , ylabel = $y$
            , domain = -1:1
            , y domain = -1:1
        , enlargelimits
        , view = {0}{90}
        , x tick label style={
             /pgf/number format/.cd,
             fixed,
             fixed zerofill,
             precision=1,
             /tikz/.cd
            }
          , y tick label style={
             /pgf/number format/.cd,
             fixed,
             fixed zerofill,
             precision=1,
             /tikz/.cd
            }  
        ]

       \addplot3[
            contour gnuplot={
                  number = 10
                 },
             thick
            ]
         {
            776.062 -50.812* x + 153.062 * y -76.812 *x *y
            };
    \end{axis}

\end{tikzpicture}

\end{document}

I have two issues with it. I could not figure out how to put both x-axes and y-axes tick labels (tick labels on all four sides) and also my code trims on the top and left side of the graph. Any help will be highly appreciated.

enter image description here

share|improve this question

1 Answer 1

up vote 4 down vote accepted
+50

Pgfplots has builtin support for one axis which receives tick labels. If you want tick labels on both sides of an axis, you can either post a feature request at sourceforge and wait for its resolution or generate a second axis for the opposite site.

Here is a solution for the approach with a second axis:

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.7}

\begin{document}

\begin{tikzpicture}

    \pgfplotsset{
        set layers,% --- CF
        , x tick label style={
             /pgf/number format/.cd,
             fixed,
             fixed zerofill,
             precision=1,
             /tikz/.cd
            }
          , y tick label style={
             /pgf/number format/.cd,
             fixed,
             fixed zerofill,
             precision=1,
             /tikz/.cd
            },
    }

    \begin{axis}[
        %   title = {$x \exp(-x^2-y^2)$}
        , xlabel = $x$
            , ylabel = $y$
            , domain = -1:1
            , y domain = -1:1
        , enlargelimits
        , view = {0}{90}
        , extra description/.code={% --- CF
                \xdef\XMIN{\pgfkeysvalueof{/pgfplots/xmin}}
                \xdef\XMAX{\pgfkeysvalueof{/pgfplots/xmax}}
                \xdef\YMIN{\pgfkeysvalueof{/pgfplots/ymin}}
                \xdef\YMAX{\pgfkeysvalueof{/pgfplots/ymax}}
        },
        ]

       \addplot3[
            contour gnuplot={
                  number = 10
                 },
             thick
            ]
         {
            776.062 -50.812* x + 153.062 * y -76.812 *x *y
            };

    \end{axis}

    \begin{axis}[% --- CF
        xmin=\XMIN,
        xmax=\XMAX,
        ymin=\YMIN,
        ymax=\YMAX,
        ticklabel pos=right,
    ]
    \end{axis}

\end{tikzpicture}

\end{document}

enter image description here

As you see, I extracted common options using a \pgfplotsset and wrote two axis environments. In addition, I automatically remembered the axis limits of the first axis and replicated them in the second. Note that the set layers statement synchronizes the layers of the two axes which is convenient especially if you plan to add grid lines. The solution currently draws the axis paths twice (except for the labels). That could be improved by means of axis lines statements.

Concerning your question about "trimming": could you add more details on what you mean here?

share|improve this answer
    
Thanks a lot @Christian for nice solution. Much appreciated. –  MYaseen208 Jan 14 '13 at 5:17
    
Can you help me to get the second (right) y-axis right aligned. Thanks –  MYaseen208 Aug 7 at 17:09
    
I am sure we can help you with the axis. However, it would help others much more if you'd simply ask a new question of sorts "How can I align an axis (or ticklabels?) to the right". The minimal example could simply contain the second axis (no need for the first one). If you say "right aligned", do you mean "the tick labels should be right aligned" or do you mean that the tick lines should point outside? –  Christian Feuersänger Aug 8 at 6:18

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.