4

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.

  • 2
    I'm not 100% sure, but I think that option goes only inside the axis environment. – Alenanno Dec 13 '15 at 18:31
  • Your MWE work fine, however, labels are not rotate ... – Zarko Dec 13 '15 at 18:34
  • @Alenanno, you are right. After tikzpicture, you can see extra tabs where I had put the axis environment. But my code hangs every time. I didn't put that here as I am not sure what I am doing wrong. – algoProg Dec 13 '15 at 18:40
7

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}
  • FYI, I started exploring axis environment and have converted my other figures to that one. It offers great flexibility, with intuitiveness. Thanks for introduction. – algoProg Dec 14 '15 at 12:50
3

Almost the same as Alenanno answer ... however some details are different:

\documentclass{article}
    \usepackage{subfig}
    \usepackage{pgfplots}
    \pgfplotsset{compat=1.12}

    \usepackage[margin=25mm]{geometry}

\begin{document}
    \begin{figure}[h]
\subfloat[A space-filling Latin Hypercube Design    \label{fig_space_fill}]%
{
    \begin{tikzpicture} 
    \begin{axis}[
    width = 0.45\linewidth,
  xmin = 0, xmax=1,
  ymin = 0, ymax=1,
 xtick = {0.2,0.4,...,1},
 ytick = {0,0.2,...,1},
xlabel = {$x_1$},
ylabel = {$x_2$},
xticklabel style = {rotate=90,anchor=east},
   enlargelimits = false,
grid
                ] 
\addplot[only marks] coordinates { (.5,.25) (.15,.5) 
                                   (.25,.45) (.35,1.5) (.45,.35) };
    \end{axis} 
    \end{tikzpicture}
}\hfill
\subfloat[A space-filling Latin Hypercube Design    \label{fig_space_fill}]%
{
    \begin{tikzpicture}
    \begin{axis}[
    width = 0.45\linewidth,
  xmin = 0, xmax=1,
  ymin = 0, ymax=1,
 xtick = {0.2,0.4,...,1},
 ytick = {0,0.2,...,1},
xlabel = {$x_1$},
ylabel = {$x_2$},
xticklabel style = {rotate=90,anchor=east},
   enlargelimits = false,
grid
                ]
\addplot[only marks] coordinates {(.05,.25) (.15,.05) 
                                  (.25,.45) (.35,.15) (.45,.35)};
    \end{axis}
    \end{tikzpicture}
}
    \end{figure}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.