Tikz轴图外柱被切断

时间:2017-08-21 07:37:03

标签: charts latex tikz

虽然图表足够宽(轴线样式),但以下图表的外部列被截断。设置图表的宽度也无济于事。任何的想法?当我增加条宽时,我需要设置或放大什么?

\begin{tikzpicture}
    \begin{axis}[
    ybar, 
    bar width=0.6cm,
    tick align=inside,
    major grid style={draw=white},
    enlarge y limits={value=.1,upper},
    ymin=0, ymax=100,
    axis x line*=bottom,
    axis y line*=right,
    hide y axis,axis line style={shorten >=-15pt, shorten <=-15pt},
    symbolic x coords={Total, Women, Men},
    xtick=data,
    nodes near coords={\pgfmathprintnumber[precision=0]{\pgfplotspointmeta} }
    ]
    \addplot [draw=none, fill=blue!30] coordinates {
        (Total,75.4064)
        (Women, 72.7961) 
        (Men,94.4597) };
    \addplot [draw=none,fill=red!30] coordinates {
        (Total,75.4064)
        (Women, 89.7961) 
        (Men,94.4597) };
    \addplot [draw=none, fill=green!30] coordinates {
        (Total,75.4064)
        (Women, 89.7961) 
        (Men,94.4597) };
    \legend{}
    \end{axis}
\end{tikzpicture}

enter image description here

1 个答案:

答案 0 :(得分:2)

您可以增加width并缩小条形组之间的空间(enlarge x limits=0.25):

\begin{tikzpicture}
    \begin{axis}[
    ybar, 
    bar width=0.6cm,
    enlarge x limits=0.25,
    width=\textwidth,
    tick align=inside,
    major grid style={draw=black},
    enlarge y limits={value=.1,upper},
    ymin=0, ymax=100,
    axis x line*=bottom,
    axis y line*=right,
    hide y axis,axis line style={shorten >=-15pt, shorten <=-15pt},
    symbolic x coords={Total, Women, Men},
    xtick=data,
    nodes near coords={\pgfmathprintnumber[precision=0]{\pgfplotspointmeta} }
    ]
    \addplot [draw=none, fill=blue!30] coordinates {
        (Total,75.4064)
        (Women, 72.7961) 
        (Men,94.4597) };
    \addplot [draw=none,fill=red!30] coordinates {
        (Total,75.4064)
        (Women, 89.7961) 
        (Men,94.4597) };
    \addplot [draw=none, fill=green!30] coordinates {
        (Total,75.4064)
        (Women, 89.7961) 
        (Men,94.4597) };
    \legend{}
    \end{axis}
\end{tikzpicture}

enter image description here