tikzpicture 轴 - 增加列之间的间距

tikzpicture 轴 - 增加列之间的间距

因此此时我有类似这样的事情:

\documentclass[12pt,twoside]{report}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{siunitx}

\pgfplotstableread[row sep=\\,col sep=&]{
    simname     &   default &   rmat    &   cshell  \\
    Weight      &   129.534 &   115.513 &   160     \\
    F1L         &   274.284 &   259.129 &   250     \\
    F1U         &   415.562 &   390.701 &   400     \\
    F2L         &   275.644 &   259.812 &   270     \\
    F2U         &   417.646 &   391.786 &   380     \\
    F3L         &   202.006 &   190.666 &   200     \\
    F3U         &   307.157 &   288.078 &   300     \\
    F4U         &   378.968 &   356.684 &   378     \\
    F5U         &   380.832 &   357.582 &   360     \\
    F6U         &   281.980 &   263.626 &   270     \\
}\stressdata

\pgfplotsset{
    /pgfplots/my legend/.style={
        legend image code/.code={
            \draw[thick,red](-0.05cm,0cm) -- (0.3cm,0cm);%
        }
    }
}

\begin{document}
    \begin{tikzpicture}
    \begin{axis}[
    width  = \textwidth,
    height = 8cm,
    major x tick style = transparent,
    ybar=2*\pgflinewidth,
    bar width=5pt,
    ymajorgrids = true,
    ylabel={Stress \si{\mega\pascal}},
    symbolic x coords={Weight, F1L, F1U, F2L, F2U, F3L, F3U, F4U, F5U, F6U},
    xtick = data,
    scaled y ticks = false,
    enlarge x limits=0.25,
    ymin=0,ymax=550,
    legend cell align=left,
    legend style={
        at={(1,1.05)},
        anchor=south east,
        column sep=1ex
    },
        extra y ticks = 505,
        extra y tick labels={},
        extra y tick style={grid=major,major grid style={thick,draw=red}}
    ]
    \addplot table[x=simname,y=default] {\stressdata};
    \addplot table[x=simname,y=rmat]    {\stressdata};
    \addplot table[x=simname,y=cshell]  {\stressdata};
    \legend{Default, Removed Material, Complex Shell}
    \addlegendimage{my legend}
    \addlegendentry{Material Yield Stress}
    \end{axis}
\end{tikzpicture}
\end{document}

得出这个数字

我正在寻找一种将列推到页面边缘的方法,以便更好地利用空间,并且列本身可以变得更大一些而不会彼此叠加。

提前致谢。

编辑:不确定这个 MWE 是否有效,很抱歉。

答案1

让我将我的评论延伸到答案......

随着enlarge x limits=0.25你扩大条形图和轴左右边界之间的空间。删除它,整个轴空间就可用于你的图表了。删除它们你将获得以下结果:

在此处输入图片描述

\documentclass[12pt,twoside]{report}
\usepackage{siunitx}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16,
    /pgfplots/my legend/.style={
       legend image code/.code={
            \draw[thick,red](-0.05cm,0cm) -- (0.3cm,0cm);%
        }
    }
}

\pgfplotstableread[row sep=\\,col sep=&]{
    simname     &   default &   rmat    &   cshell  \\
    Weight      &   129.534 &   115.513 &   160     \\
    F1L         &   274.284 &   259.129 &   250     \\
    F1U         &   415.562 &   390.701 &   400     \\
    F2L         &   275.644 &   259.812 &   270     \\
    F2U         &   417.646 &   391.786 &   380     \\
    F3L         &   202.006 &   190.666 &   200     \\
    F3U         &   307.157 &   288.078 &   300     \\
    F4U         &   378.968 &   356.684 &   378     \\
    F5U         &   380.832 &   357.582 &   360     \\
    F6U         &   281.980 &   263.626 &   270     \\
}\stressdata


\begin{document}
    \begin{tikzpicture}
    \begin{axis}[
    width  = \textwidth,
    height = 8cm,
    major x tick style = transparent,
    ybar=2*\pgflinewidth,
    bar width=7pt,              % <--- increased
    ymajorgrids = true,
    ylabel={Stress \si{\mega\pascal}},
    symbolic x coords={Weight, F1L, F1U, F2L, F2U, F3L, F3U, F4U, F5U, F6U},
    xtick = data,
    scaled y ticks = false,
    %enlarge x limits=0.25,    % <--- removed
    ymin=0,ymax=550,
    legend cell align=left,
    legend style={
        at={(1,1.05)},
        anchor=south east,
        column sep=1ex
    },
        extra y ticks = 505,
        extra y tick labels={},
        extra y tick style={grid=major,major grid style={thick,draw=red}}
    ]
    \addplot table[x=simname,y=default] {\stressdata};
    \addplot table[x=simname,y=rmat]    {\stressdata};
    \addplot table[x=simname,y=cshell]  {\stressdata};
    \legend{Default, Removed Material, Complex Shell}
    \addlegendimage{my legend}
    \addlegendentry{Material Yield Stress}
    \end{axis}
\end{tikzpicture}
\end{document}

相关内容