组图中的刻度未按预期显示

组图中的刻度未按预期显示

我正在制作一个组图(仍在进行中)。我在这里遇到的问题是刻度没有按预期显示。我查看了我的代码,似乎不明白如何修复它们。非常感谢您的帮助。这是我的代码

    \begin{tikzpicture}

\definecolor{saffron}{HTML}{FF9933}
\definecolor{brickred}{HTML}{F96302}

\begin{groupplot}[scale=0.55, group style={
                                        every axis plot post/.style={/pgf/number format/fixed},
                    group name=relcost, columns=3,
                    horizontal sep=2.1cm,
                    xlabels at=edge bottom,
                    ylabels at=edge left},
                    ybar=1pt,
                    xmin=1,xmax=7,
                    ymin=0,ymax=150,
                    axis on top,
                    restrict y to domain*=0:180,
                    ytick={2,4,6},
                    xtick={0,50,100,150},                   
                    xticklabel = $\pgfmathprintnumber{\tick}$,
                    yticklabel = $\pgfmathprintnumber{\tick}$,
%                   x post scale=0.56,
%                   y post scale=0.56,
                                        %axis on top,
                                        visualization depends on=rawy\as\rawy,
                                        before end axis/.code={ % Draw line indicating break
                                        \draw [ultra thick, white, decoration={snake, amplitude=1pt}, decorate] (rel axis cs:0,0.95) -- (rel axis cs:1,0.95);
                                        },
                                        %axis lines*=left,
                                        clip=true,
                    ylabel={PoR (\%)},legend columns = -1,
                    legend style={font=\small},
                                        /tikz/every even column/.append style={column sep=0.5cm}]
\nextgroupplot[title=\textsc{india35}, xlabel={Bands}]
    \addplot+ [bar width=5pt,draw=brickred,fill=brickred!65!white]
        coordinates {
            (2, 89.19384318051064)
            (4, 29567.029897109864)
            (6, 35440.15753233791)
        };
    \addplot+ [bar width=5pt,draw=brickred,fill=brickred!65!white]
        coordinates {
            (2, 68.24614074707121)
            (4, 99.12252870172907)
            (6, 107.10846914449084)
        };
    \addplot+ [bar width=5pt,draw=saffron,fill=saffron!65!white]
        coordinates {
            (2, 60.67834554810314)
            (4, 92.21315039496554)
            (6, 101.04988585747812)
        };
    \addplot+ [bar width=5pt,draw=black,fill=saffron!60!white]
        coordinates {
            (2, 59.39716477127379)
            (4, 91.03110772519211)
            (6, 101.89592802451237)
        };
\nextgroupplot[title=\textsc{janos-us}, xlabel={Bands}]
    \addplot+  [bar width=5pt]
        coordinates {
            (2, 83.05)
            (4, 8299.46)
            (6, 10086.44)
        };
    \addplot+  [bar width=5pt]
        coordinates {
            (2, 35.52)
            (4, 50.07)
            (6, 54.01)
        };
    \addplot+ [bar width=5pt]
        coordinates {
            (2, 30.95)
            (4, 47.56)
            (6, 52.75)
        };
    \addplot+ [bar width=5pt]
        coordinates {
            (2, 30.88)
            (4, 46.97)
            (6, 52.11)
        };
\nextgroupplot[title=\textsc{norway}, xlabel={Bands}, legend to name=unnamed]
    \addplot+ [bar width=5pt]
        coordinates {
            (2, 132.85)
            (4, 10934.75)
            (6, 13211.21)
        };
        \addlegendentry{Exact}
    \addplot+ [bar width=5pt]
        coordinates {
            (2, 32.25)
            (4, 49.77)
            (6, 54.25)
        };
                \addlegendentry{SP}
    \addplot+ [bar width=5pt]
        coordinates {
            (2, 30.38)
            (4, 48.89)
            (6, 53.94)
        };
                \addlegendentry{BRKGA-I}
    \addplot+ [bar width=5pt]
        coordinates {
            (2, 30.24)
            (4, 48.19)
            (6, 53.62)
        };
                \addlegendentry{BRKGA-II}
\end{groupplot}
\node at (relcost c2r1.south) [inner sep=0pt, anchor=north, yshift=-6.5ex] {\ref{unnamed}};
\end{tikzpicture}

在此处输入图片描述

答案1

看来你交换xtickytick 标签。如果你将替换

ytick={2,4,6},
xtick={0,50,100,150}, 

ytick={0,50,100,150}, 
xtick={2,4,6},

你会得到你想要的结果。然而,˙tivk`位置的定义不是必需的。你可以删除这两行。

\documentclass[margin=3mm]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{groupplots}
\pgfplotsset{compat=1.16}
\definecolor{saffron}{HTML}{FF9933}
\definecolor{brickred}{HTML}{F96302}
\usepackage{siunitx}


\begin{document}
    \begin{tikzpicture}
\begin{groupplot}[scale=0.6,
group style={every axis plot post/.style={/pgf/number format/fixed},
             group name=relcost, 
             columns=3,
             horizontal sep=12mm,
             xlabels at=edge bottom,
             ylabels at=edge left,
             },
%
ybar=1pt,
xmin=1,xmax=7,
ymin=0,ymax=150,
axis on top,
restrict y to domain*=0:180,
before end axis/.code={ % Draw line indicating break of bars
    \draw [ultra thick, white, 
           decoration={snake, amplitude=1pt}, decorate] 
           (rel axis cs:0,0.95) -- (rel axis cs:1,0.95);
                    },
ylabel={PoR (\si{\percent})},
%
legend columns = -1,
legend style={at={(0.2,-0.35)}, font=\small},
/tikz/every even column/.append style={column sep=5mm}
            ]
%%%% first diagram
\nextgroupplot[title=\textsc{india35},
               xlabel={Bands}]
\addplot+ [bar width=5pt,draw=brickred,fill=brickred!65!white]
    coordinates {
        (2, 89.19384318051064)
        (4, 29567.029897109864)
        (6, 35440.15753233791)
    };
\addplot+ [bar width=5pt,draw=brickred,fill=brickred!65!white]
    coordinates {
        (2, 68.24614074707121)
        (4, 99.12252870172907)
        (6, 107.10846914449084)
    };
\addplot+ [bar width=5pt,draw=saffron,fill=saffron!65!white]
    coordinates {
        (2, 60.67834554810314)
        (4, 92.21315039496554)
        (6, 101.04988585747812)
    };
\addplot+ [bar width=5pt,draw=black,fill=saffron!60!white]
    coordinates {
        (2, 59.39716477127379)
        (4, 91.03110772519211)
        (6, 101.89592802451237)
    };
%%%% second diagram
\nextgroupplot[title=\textsc{janos-us},
               xlabel={Bands},
               ]
\addplot+  [bar width=5pt]
    coordinates {
        (2, 83.05)
        (4, 8299.46)
        (6, 10086.44)
    };
\addplot+  [bar width=5pt]
    coordinates {
        (2, 35.52)
        (4, 50.07)
        (6, 54.01)
    };
\addplot+ [bar width=5pt]
    coordinates {
        (2, 30.95)
        (4, 47.56)
        (6, 52.75)
    };
\addplot+ [bar width=5pt]
    coordinates {
        (2, 30.88)
        (4, 46.97)
        (6, 52.11)
    };
%%%% third diagram
\nextgroupplot[title=\textsc{norway},
               xlabel={Bands},
               ]
\addplot+ [bar width=5pt]   coordinates {
        (2, 132.85)
        (4, 10934.75)
        (6, 13211.21)
    };
    \addlegendentry{Exact}
\addplot+ [bar width=5pt]   coordinates {
        (2, 32.25)
        (4, 49.77)
        (6, 54.25)
    };
            \addlegendentry{SP}
\addplot+ [bar width=5pt]   coordinates {
        (2, 30.38)
        (4, 48.89)
        (6, 53.94)
    };
            \addlegendentry{BRKGA-I}
\addplot+ [bar width=5pt]   coordinates {
        (2, 30.24)
        (4, 48.19)
        (6, 53.62)
    };
            \addlegendentry{BRKGA-II}
\end{groupplot}
    \end{tikzpicture}
\end{document}

上述 mwe 的结果是:

在此处输入图片描述

相关内容