答案1
如果您使用表格数据进行绘图,这里有一些解决方案
\documentclass[tikz,margin=3.14mm]{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis equal,
axis x line=bottom,axis y line=left,
enlargelimits=true,
legend style={at={(0,1.05)},anchor=south west},
]
% If you want the vertical line at x=0
\addplot+ table{
-3 1
-2 1
-1 0
0 0
0 1
1 1
2 0
3 0
};
% If you want the vertical line at x=0
\addplot+ table{
-3 1
-2 1
-1 0
0 0
0 1
1 1
2 0
3 0
};
% If you want the vertical line at x=0
\addplot+[dashed,unbounded coords=jump] table{
-3 1
-2 1
-1 0
0 0
0 nan
0 1
1 1
2 0
3 0
};
\legend{default,empty line in table, nan in table + "unbounded coords=jump"}
\end{axis}
\end{tikzpicture}
\end{document}