绘图线结束于属于域的最后一个刻度标记处。是否可以将线条一直延伸到标记之外并到达图表框的边缘?
\documentclass{article}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}[font=\tiny,scale=2.2]
\begin{axis}[
axis x line=center,
axis y line=center,
restrict y to domain=-50:50,
legend entries={$d=-2$,$d=-1$,$d=0$,$d=1$,$d=2$},legend pos=north west]
]
\foreach \d in {-2, ..., 2}
{
\addplot[solid, every mark/.append style={fill=blue}, mark=*, mark size=1]{(x-\d)^3};
}
\end{axis}
\end{tikzpicture}
\end{document}
答案1
您可以通过将域明确定义为以下方式获得所需的结果domain=-4:4
:
代码:
\documentclass[border=2pt]{standalone}
\usepackage{tikz,pgfplots}
\begin{document}
\begin{tikzpicture}[font=\tiny,scale=2.2]
\begin{axis}[
axis x line=center,
axis y line=center,
restrict y to domain=-50:50,
legend entries={$d=-2$,$d=-1$,$d=0$,$d=1$,$d=2$},legend pos=north west]
]
\foreach \d in {-2, ..., 2}
{
\addplot[solid, every mark/.append style={fill=blue}, mark=*, mark size=1, domain=-4:4]{(x-\d)^3};
}
\end{axis}
\end{tikzpicture}
\end{document}