Tikz 图片,旋转 x 刻度标签

Tikz 图片,旋转 x 刻度标签

我有以下代码:

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

我正在尝试旋转 xtick 标签 (0、0.2、0.4、...、1)。我尝试使用axis以下环境:

xticklabel style={
rotate=90,
},

但我的代码每次都会挂起。我不确定哪里出了问题。

任何帮助都将不胜感激。谢谢。

答案1

我已经用 重做​​了你的图表pgfplots。我想你会喜欢更短更简单的代码。

输出

示例图片

代码

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

答案2

与 Alenanno 的回答几乎相同......但是有些细节不同:

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

在此处输入图片描述

相关内容