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 would like to draw small arrows (through a macro probably), to show the coordinate directions like the plot below. It would be nice to have the option to turn on/off the grids as well.

The MWE for generating the plot:

\documentclass[12pt]{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}

\begin{axis}
[view = {120}{10}
,grid = both
]
\addplot3[surf] {x^2+y^2};
\end{axis}

\end{tikzpicture}

\end{document}

enter image description here

share|improve this question

1 Answer 1

up vote 4 down vote accepted

A straight forward way is to set appropriate coordinates in the rel axis cs and then draw arrows outside the axis environement, such that the arrows don't get clipped by the axis.

The length of the hand drawn axis lines is controlled via \axislength. Replace \def\axislength{.2} with \def\axislength{.3} for instance to make them longer.

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\def\axislength{.2}
\begin{tikzpicture}
  \begin{axis}[view = {120}{10},ticks=none,axis lines=none]
    \coordinate (O) at (rel axis cs:1,0,0);
    \coordinate (x) at (rel axis cs:1,\axislength,0);
    \coordinate (y) at (rel axis cs:1-\axislength,0,0);
    \coordinate (z) at (rel axis cs:1,0,\axislength);
    \addplot3[surf] {x^2+y^2};
  \end{axis}
  \draw[->] (O) -- (x) node[above] {$x$};
  \draw[->] (O) -- (y) node[above] {$y$};
  \draw[->] (O) -- (z) node[right] {$z$};
\end{tikzpicture}
\end{document}

enter image description here

share|improve this answer
    
Thanks @HenriMenke! Can we make the axis lines and labels disappear? Further, can we make the arrow length independent to the coordinate xmin,xmax, etc? –  M.Reza Jul 11 at 11:23
    
@M.Reza try ticks=none for hiding the ticks. If you want to get rid of the box around the plot, try axis lines=none. –  s__C Jul 11 at 11:45
    
@M.Reza See my updated answer. –  Henri Menke Jul 11 at 12:37

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.