# pgfplot contour plot with both x-axes and y-axes ticks labels

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

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.

-

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}}
},
]

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}


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.