# TikZ 3D plot : how to add spaces between tick labels to prevent them from colliding?

I have a 3D plot with colliding yticklabels, which I have been unable to fix for now. Here is my minimum working example:

\documentclass[10pt]{standalone}
%
\usepackage[utf8]{inputenc}
\usepackage{tikz,pgfplots,amsmath}
%
%

\begin{document}
\begin{tikzpicture}
%graphique
\begin{axis}[
width=4 cm,
height=4 cm,
xmin=3,xmax=6,
ymin=0,ymax=0.023,
zmin=1,zmax=1.8,
xlabel=x,
ylabel=y,
zlabel=z,
zticklabel style = {yshift=0.1cm}, %to prevent it from colliding with xlabels
xtick = {3,4,5,6},
ytick ={0.006,0.012,0.017,0.023},
yticklabels = {0.6,1.2,1.7,2.3},
ztick ={1,1.2,1.4,1.6,1.8},
scaled y ticks = false,
view           = {30}{30},
]

\addplot3[fill=black!15,opacity=0.35,thick] (4,0,1) -- (4,0.023,1) -- (4,0.023,1.8) -- (4,0,1.8) -- cycle;

\end{axis}

\end{tikzpicture}
\end{document}


Giving for now:

Would you know a way to relax the yticklabel so that they do not collide ? The only solution I found so far was to delete it in the axis by passing yticklabels = {,,,}, only to define it manually after the \end{axis}...

PS: the axis width, height, view and the font size must not be changed ;)

• your image is small, so there is not enough space for tick labels. try to reduce tick labels' font size, for example with adding ticklabel style={font=\tiny}, to axis preamble. after than you can delete zticklabel style = {yshift=0.1cm}. – Zarko Mar 6 at 20:35
• @Zarko Thank you for your remark. I know that it is a font size problem, but I would rather move a bit labels from the ticks than change the font size or image size. Is there no way to add a bit of space between labels without positionning them by hand? – jeannej Mar 6 at 21:30
• as far as i know, only way to add more space around labels is use smaller fonts for labels or increase diagram size. – Zarko Mar 6 at 22:37

You could rotate them.

\documentclass[10pt]{standalone}
%
\usepackage[utf8]{inputenc}
\usepackage{tikz,pgfplots,amsmath}
%
%

\begin{document}
\begin{tikzpicture}
%graphique
\begin{axis}[
width=4 cm,
height=4 cm,
xmin=3,xmax=6,
ymin=0,ymax=0.023,
zmin=1,zmax=1.8,
xlabel=x,
ylabel=y,
zlabel=z,
zticklabel style = {yshift=0.1cm}, %to prevent it from colliding with xlabels
xtick = {3,4,5,6},
ytick ={0.006,0.012,0.017,0.023},
yticklabels = {0.6,1.2,1.7,2.3},
ztick ={1,1.2,1.4,1.6,1.8},
scaled y ticks = false,
yticklabel style={rotate=-30},
view           = {30}{30},
]

\addplot3[fill=black!15,opacity=0.35,thick] (4,0,1) -- (4,0.023,1) -- (4,0.023,1.8) -- (4,0,1.8) -- cycle;

\end{axis}

\end{tikzpicture}
\end{document}


• thank you, this is a cunning answer! Any hint as to why "1.2" and "1.7" seem closer to each other ? (they are touching a bit, while there is some space between "1.7" and "2.3") – jeannej Mar 8 at 17:59
• @jeannej This is because 1.7-1.2=0.5<0.6=2.3-1.7. – marmot Mar 8 at 18:01