ybar 图的 xshift

ybar 图的 xshift

我怎样才能xshift绘图ybar,以便数字显示与每个条的垂直左线对齐,而不是与中心对齐,并且每个条的宽度完全对齐25(现在看来条略大一些)?

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.8}
\pgfplotsset{compat/show suggested version = false}

\begin{document}

\begin{tikzpicture}
\begin{axis}[%
    ybar,
    bar width = 25,
    minor tick num = 4,
    nodes near coords,
    ]
    \addplot[thick,fill=blue!50] coordinates {%
        (0,1)
        (50,0.3)
        (100,0.2)
        (150,0.2)
        (200,0.1)
        };
\end{axis}
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案1

您可以使用bar shift选项。

\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat = 1.8}
\pgfplotsset{compat/show suggested version = false}

\begin{document}

\begin{tikzpicture}
\begin{axis}[%
    ybar,
    bar width = 25,
    minor tick num = 3,
    nodes near coords,bar shift=12.5
    ]
    \addplot[thick,fill=blue!50] coordinates {%
        (0,1)
        (50,0.3)
        (100,0.2)
        (150,0.2)
        (200,0.1)
        };
\end{axis}
\end{tikzpicture}

\end{document}

如果你的目标是 25 个增量,你还需要 3 个小刻度

在此处输入图片描述

相关内容