我有这个代码
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel=Retraso,ylabel=Autocorrelación,ybar,bar width=1pt]
\foreach \x in {0,...,15}{
\addplot [color=blue,fill=blue] coordinates{
(\x,0.8^\x)
};
}
\end{axis}
\end{tikzpicture}
\end{document}
但当我编译它时,我有这个
我想将x
坐标与条形图对齐。我该怎么做?
答案1
ycomb
一种用 代替 的解决方案bar
。
\documentclass[12pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel=Retraso,ylabel=Autocorrelación]
\foreach \x in {0,...,15}{
\addplot [color=blue,fill=blue,ycomb,line width=2pt] coordinates{
(\x,0.8^\x)
};
}
\end{axis}
\end{tikzpicture}
\end{document}
答案2
\documentclass{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.12}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xlabel=Retraso,ylabel=Autocorrelación,ybar,bar width=1pt,samples at={0,...,15}]
\addplot[draw=blue,fill=blue] {0.8^\x};
\end{axis}
\end{tikzpicture}
\end{document}