我怎样才能将条形图的左侧与它们“分配”的 x 值对齐?
在我的条形图中,第一个条形与 y 轴重叠,但我希望它位于 y 轴的右侧。
因此,对于所有条形图,它们的中心不是与相应的 x 值对齐,而是它们的左边缘对齐。
我怎么做?
\begin{tikzpicture}
\begin{axis}[
axis lines = center,
axis line style = {-},
xlabel = $$,
ylabel = $$,
xmin = 0,
xmax = 0.001,
clip=false,
xtick = {0, 0.001},
xticklabels = {,},
ymin = -1,
ymax = 1,
ytick = {-1,0,1},
height = 10em,
width = 30em,
]
\addplot [
ybar,
fill=blue,
bar width=0.000005,
draw=none,
]
coordinates {
(0,0.00928)
(0.00002083333,0.23672)
(0.00004166667,0.31467)
(0.0000625,0.58179)
(0.00008333333,0.46774)
(0.0001041667,0.71017)
(0.000125,0.45074)
};
\end{axis}
\end{tikzpicture}
答案1
默认情况下,您会得到以 x 坐标为中心的条形图,但可以使用参数进行修改bar shift
。您只需设置bar shift=0.0000025
,即一半bar width
。
\documentclass[12pt]{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.15}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis lines = center,
axis line style = {-},
xlabel = $$,
ylabel = $$,
xmin = 0,
xmax = 0.0002,
clip=false,
xtick = {0, 0.001},
xticklabels = {,},
ymin = -1,
ymax = 1,
ytick = {-1,0,1},
height = 10em,
width = 30em,
ybar,
]
\addplot [
fill=blue,
bar width=0.000005,
bar shift=0.0000025,
draw=none,
]
coordinates {
(0,0.00928)
(0.00002083333,0.23672)
(0.00004166667,0.31467)
(0.0000625,0.58179)
(0.00008333333,0.46774)
(0.0001041667,0.71017)
(0.000125,0.45074)
};
\end{axis}
\end{tikzpicture}
\end{document}