答案1
在图书馆的帮助下intersections
:
\documentclass[border=3.141592]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[
dot/.style = {circle, draw, solid, fill=gray, inner sep=1.6pt,
node contents={}},
]
\begin{axis}[name=plot1,
declare function = {f(\x)=0.5*(x-2)^3-0.2*x+2;},% actual function is unknown
axis lines = left,
xlabel={$x$}, ylabel={$\phi_l(x)$},
xtick=\empty,
xmin=0, xmax=4.2,
ymin=0,
restrict y to domain=0:4.4,
no marks, samples=1000, domain=0:4,
every axis plot post/.append style={very thick},
clip=false
]
\addplot+[thick,name path=P]{f(x)};
%
\path[name path=A] (0,1) -- (4,1);
\path[name path=B] (0,2) -- (4,2);
\path[name path=C] (0,3) -- (4,3);
\path[name path=D] (0,4) -- (4,4);
%
\path[name intersections={of = P and A, by=x1}];
\path[name intersections={of = P and B, by=x2}];
\path[name intersections={of = P and C, by=x3}];
\path[name intersections={of = P and D, by=x4}];
%
\draw[densely dashed, very thin]
(0,1) -| (x1 |- 0,0) node[dot]
(0,2) -| (x2 |- 0,0) node[dot]
(0,3) -| (x3 |- 0,0) node[dot]
(0,4) -| (x4 |- 0,0) node[dot];
\end{axis}
\end{tikzpicture}
\end{document}
如果您喜欢带阴影的点节点,则需要将dot
样式修改为:
dot/.style = {circle, draw, solid, semithick,
left color=gray!10, right color=gray!90, inner sep=1.6pt,
node contents={}},
在这种情况下,图表如下: