[Tex/LaTex] Tikz picture, rotate x tick labels

pgfplotsrotatingtikz-pgf

I have following code:

\documentclass{article}
\usepackage{tikz,amsmath}
\usepackage{subfig}
\usepackage{pgfplots}
\begin{document}
    \begin{figure}[!t]
        \centering
        \subfloat[A space-filling Latin Hypercube Design]{\label{fig_space_fill}
            \begin{tikzpicture}[scale=0.45, font = \scriptsize]%
                %\begin{axis}[
                    \draw[step=1cm,black,thin] (0,0) grid (5,5);
                    \foreach \xtick in {0,...,5} {\pgfmathsetmacro\result{\xtick * .2} \node at (\xtick,-0.5) {\pgfmathprintnumber{\result}}; },
                    \foreach \ytick in {0,...,5} {\pgfmathsetmacro\result{\ytick * .2} \node at (-.5,\ytick) {\pgfmathprintnumber{\result}}; },
                    %xticklabel style={
                        %rotate=90,
                    %},
                    %]
                    \foreach \x/\y in {.5/2.5, 1.5/.5, 2.5/4.5, 3.5/1.5, 4.5/3.5}{\draw [fill=black, thin] (\x,\y) circle [radius=0.05];},
                    \node at (2.5,-1) {$x1$};
                    \node at (-1.3,2.5) {$x2$};
                %\end{axis}
            \end{tikzpicture}%  
        }
        \qquad
        \subfloat[A non-space-filling Latin Hypercube Design]{\label{fig_no_space_fill}
            \begin{tikzpicture}[scale=0.45, font = \scriptsize]%
                %\begin{axis}[
                    \draw[step=1cm,black,thin] (0,0) grid (5,5);
                    \foreach \xtick in {0,...,5} {\pgfmathsetmacro\result{\xtick * .2} \node at (\xtick,-0.5) {\pgfmathprintnumber{\result}}; },
                    \foreach \ytick in {0,...,5} {\pgfmathsetmacro\result{\ytick * .2} \node at (-.5,\ytick) {\pgfmathprintnumber{\result}}; },
                    %xticklabel style={
                        %rotate=90,
                    %},
                    %]
                    \foreach \x/\y in {.5/.5, 1.5/1.5, 2.5/2.5, 3.5/3.5, 4.5/4.5}{\draw [fill=black, thin] (\x,\y) circle [radius=0.05];}
                    \node at (2.5,-1) {$x1$};
                    \node at (-1.3,2.5) {$x2$};
                %\end{axis}
            \end{tikzpicture}%      
        }
        \caption{Two instances of Latin Hypercube Design}
        \label{space_filling}
    \end{figure}
\end{document}

I am trying to rotate the xtick labels (0, 0.2, 0.4,…,1). I tried using axis environment with:

xticklabel style={
rotate=90,
},

But my code hangs every time. I am not sure what's wrong.

Any help will be appreciated. Thanks.

Best Answer

I have redone your graphs with pgfplots. I think you will appreciate the shorter and easier code.

Output

example image

Code

\documentclass{article}
\usepackage{tikz,amsmath}
\usepackage{subfig}
\usepackage{pgfplots}

\pgfplotsset{compat=1.12}
\begin{document}
    \begin{figure}[!t]
        \centering
        \subfloat[A space-filling Latin Hypercube Design]{\label{fig_space_fill}
            \begin{tikzpicture}[scale=0.45]%
            \begin{axis}[
                grid=both,
                xmin=0,xmax=1,
                ymin=0,ymax=1,
                xtick={0.2,0.4,0.6,0.8,1},
                ytick={0,0.2,0.4,0.6,0.8,1},
                axis equal image,
                major grid style={black},
                xticklabel style={rotate=90},
                tick label style={font=\boldmath},
                enlargelimits=false,
                ]
                \foreach \x/\y in {.1/.5,.3/.1,.5/.9,.7/.3,.9/.7}{
                    \addplot[only marks] coordinates {(\x,\y)};
                }
            \end{axis}
            \end{tikzpicture}%  
        }
        \qquad
        \subfloat[A non-space-filling Latin Hypercube Design]{\label{fig_no_space_fill}
            \begin{tikzpicture}[scale=0.45]%
                \begin{axis}[
                        grid=both,
                        %tick={0,0.2,...,1},
                        xmin=0,xmax=1,
                        ymin=0,ymax=1,
                        xtick={0.2,0.4,0.6,0.8,1},
                        ytick={0,0.2,0.4,0.6,0.8,1},
                        axis equal image,
                        major grid style={black},
                        xticklabel style={rotate=90},
                        tick label style={font=\boldmath},
                        enlargelimits=false,
                    ]
                \foreach \cr in {.1,.3,.5,.7,.9}{
                    \addplot[only marks] coordinates {(\cr,\cr)};
                }
            \end{axis}
            \end{tikzpicture}%      
        }
        \caption{Two instances of Latin Hypercube Design}
        \label{space_filling}
    \end{figure}
\end{document}