2

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}
%
\pgfplotsset{compat=newest}
%

\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:

minimum working example initial result, with yticklabels colliding

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

Thank you for your time!

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

3
  • 1
    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, 2019 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, 2019 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, 2019 at 22:37

1 Answer 1

2

You could rotate them.

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

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

enter image description here

2
  • 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, 2019 at 17:59
  • 1
    @jeannej This is because 1.7-1.2=0.5<0.6=2.3-1.7.
    – user121799
    Mar 8, 2019 at 18:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .