答案1
我的尝试非常简单,我认为结果也差不多(我知道可能不那么顺利)。但这可能比尝试随机路径更容易。
这是我的代码:
\documentclass{standalone}
\usepackage {pgfplots}
\pgfplotsset {compat=1.17,axis on top}
\begin{document}
\begin{tikzpicture}
\begin{axis}
[
clip=false,
title = \bf{}Plot,
xmin=-30, xmax=30,
ymin=-100, ymax=300,
axis lines=center,
minor x tick num={9},
minor y tick num={9},
xlabel=X-Axis,
ylabel=Y-Axis,
legend style={anchor=south west,at={(0,.3)}},
samples=50
]
\pgfplotsinvokeforeach{1,...,300}
{
% Positive X-Axis
\fill[pink!55] (14*rand+16,7*rand) circle (3pt);
% Negative X-Axis
\fill[blue!35] (-14*rand-16,7*rand) circle (3pt);
% Positive Y-Axis
\fill[green!35] (rand,140*rand+160) circle (3pt);
}
% Blue line
\addplot[thick, blue] coordinates {(-15,-100) (25,300)};
\addlegendentry{Line}
\end{axis}
\end{tikzpicture}
\end{document}