![使用 PGF 图重建图形](https://linux22.com/image/458398/%E4%BD%BF%E7%94%A8%20PGF%20%E5%9B%BE%E9%87%8D%E5%BB%BA%E5%9B%BE%E5%BD%A2.png)
我正在尝试使用 PGF 图重新创建附图。有没有更简单的方法可以做到这一点?有没有办法绘制或创建类似这样的函数,而不必知道函数的方程式?我尝试使用 hobby 包并估计曲线的点,但没有成功。
我知道我可以截取图片,但看起来不太好。我真的很想学习如何更有效地做到这一点。我正在尝试使用二次方程,但正如你所见,我的图不完整。我希望这是可能的。我也想知道如何用箭头绘制 f(x) 标签节点。
任何帮助,将不胜感激。
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{graphics}
\usepackage{graphicx}
\usetikzlibrary{hobby}
\pgfplotsset{compat=newest}
\tikzset{point/.style={circle,draw=black,inner sep=0pt,minimum size=3pt}}
\usetikzlibrary{arrows.meta}
\usepackage[labelformat=empty]{caption}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[grid style={gray!50}, thick,
xlabel={\(x\)},
ylabel={\(y\)}, xmin=-4,xmax=6,ymin=-5,ymax=5,
every axis plot/.append style={ultra thick},
axis y line=center,
axis x line=center,
axis line style={Triangle-Triangle},
ticklabel style={font=\small,fill=white},
yticklabels=\empty,
ytick=\empty
]
\addplot[thick,samples=1000,domain=-3:-2]{-2*(x+3)^2+2};
\addplot[thick,samples=1000,domain=0:2]{-(x-1)^2};
\addplot[thick,samples=1000,domain=-2:-1]{.5(x+1)^2-2};
\draw[thick, dashed] (-3,0)--(-3,2);
\addplot[thick,samples=1000,domain=3:5]{-(x-5)^2+2};
\draw[thick, dashed] (-3,0)--(-3,2);
\draw[thick,dashed] (5,0)--(5,2);
\draw[thick,dashed] (3,0)--(3,-3);
\draw[thick,dashed] (-1,0)--(-1,-2);
\end{axis}
\end{tikzpicture}
\caption{}
\end{figure}
\end{document}
更新:有人关闭了此操作,但不清楚原因。这是同事 STEFAN 提供的解决方案。
您可以将原始图像作为节点包含在内,绘制网格以查看坐标,然后选择尽可能多的坐标值并绘制平滑的图,然后删除图像节点:
\documentclass[tikz,border=10pt]{standalone}
\begin{document}
\begin{tikzpicture}
%\node[opacity=0.5] at (2.8,1.2) {\includegraphics{screenshot}};
\draw[thin,dotted] (-8,-5) grid (12,3);
\draw[->] (-8,0) -- (13,0);
\draw[->] (0,-5) -- (0,7);
\draw plot [smooth,tension=0.7] coordinates {
(-6.3,2.5) (-5.4,2) (-4.7,1) (-4,-0.5) (-3,-3) (-2,-3.6)
(-1,-3) (0,-1.8) (1,-0.5) (2,0) (3,-0.5) (4,-1.8) (5,-3.2)
(6.1,-4.1) (7,-3.2) (8,-0.6) (9,1) (10,2) (10.5,2.1)
};
\end{tikzpicture}
\end{document}
'''
答案1
通过您的所有序言和此代码:
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\usepackage{graphics}
\usepackage{graphicx}
\usetikzlibrary{hobby}
\pgfplotsset{compat=newest}
\tikzset{point/.style={circle,draw=black,inner sep=0pt,minimum size=3pt}}
\usetikzlibrary{arrows.meta}
\usepackage[labelformat=empty]{caption}
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
\begin{axis}[grid style={gray!50}, thick,
xlabel={\(x\)},
ylabel={\(y\)}, xmin=-4,xmax=6,ymin=-5,ymax=5,
every axis plot/.append style={ultra thick},
axis y line=center,
axis x line=center,
axis line style={Triangle-Triangle},
ticklabel style={font=\small,fill=white},
yticklabels=\empty,
ytick=\empty
]
\addplot[cyan,thick,samples=1000,domain=-3:5]{cos(3*x*180/pi)-2*(sin(x*180/pi))^2};
\end{axis}
\end{tikzpicture}
\caption{Guess the equation of the function}
\end{figure}
\end{document}
你有这个输出:
但我们需要知道函数方程你需要绘制。