通过虚线连接图形上的点

通过虚线连接图形上的点

我怎样才能用虚线和垂直线连接这些点?

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[axis lines=center]
\addplot [only marks] table{
0 0.00390625
1 0.05078125
2 0.26171875
3 0.68359375
4 1
};
\addplot [domain=0:1] {0.00390625};
\addplot [domain=1:2] {0.05078125};
\addplot [domain=2:3] {0.26171875};
\addplot [domain=3:4] {0.68359375};
\addplot [domain=4:5] {1};
\end{axis}
\end{tikzpicture}

\end{document}

答案1

像这样?

\documentclass{article}
\usepackage{pgfplots}

\begin{document}

\begin{tikzpicture}
\begin{axis}[axis lines=center]
\addplot [only marks] table{
0 0.00390625
1 0.05078125
2 0.26171875
3 0.68359375
4 1
};
\addplot [domain=0:1] {0.00390625}coordinate[pos=1](b);
\addplot [domain=1:2] {0.05078125}coordinate[pos=0](c)coordinate[pos=1](d);
\addplot [domain=2:3] {0.26171875}coordinate[pos=0](e)coordinate[pos=1](f);
\addplot [domain=3:4] {0.68359375}coordinate[pos=0](g)coordinate[pos=1](h);
\addplot [domain=4:5] {1}coordinate[pos=0](i);
\draw[thick,dotted,red] (b) -- (c)(d) -- (e) (f) -- (g) (h) -- (i);
\end{axis}
\end{tikzpicture}

\end{document}

enter image description here

我已经根据图表定义了坐标,然后绘制线条就变成了一件正式的事情。

相关内容