如何在 tikz 中制作带有控件的图表?

如何在 tikz 中制作带有控件的图表?

我正在制作逐点图,如何才能更有效地完成。我想得到以下图形

在此处输入图片描述

 \documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{calc}

\begin{document}

\begin{tikzpicture}
\begin{scope}[]
    \draw[->,line width = 1.5pt] (3,3.2) -- (0.5,0.5) node[left]{$x_1$};
    \draw[->,line width = 1.5pt] (3,3.2) -- (3,7.5) node[left]{$y$};
    \draw[line width = 1.5pt] (3,3.2) -- (5.7,3.2) ;
    \draw[->,line width = 1.5pt] (8.6,3.2) -- (10.5,3.2) node[right]{$x_2$};
   \draw[red,line width = 1.5pt] (4.5,0.85) .. controls(4.28,1.2).. (4.28,1.5) .. controls(4.33,1.7).. (4.5,1.85) .. controls(5,2.2) and (5.25,2.4) .. (5.5,2.9) .. controls(5.8,3.2) and (6.25,4.8).. (6.4,5) .. controls(6.7,5.5).. (7,5.75) .. controls(7.45,5.91).. (7.9,5.7);
   % \node[circle (2.5pt)] at (2,5.3) {};
    \draw [fill=black] (5.45,1.55) circle (2.5pt);
    \draw [fill=black] (6.8,1.85) circle (2.5pt);
    \node at (6.5,1.5) [left]{$S$};
\end{scope}

\end{tikzpicture}

\end{document}

在此处输入图片描述

答案1

这是一张快速绘制的草图用手,这说明它的准确度不符合您的需求,但它可以帮助您入门。

\documentclass[tikz,border=3.14mm]{standalone}
\begin{document}
    \begin{tikzpicture}
        \draw [purple,line width=2pt]
                (0,2)   .. controls ++(0.25,1)  and ++(-0.8,-2) ..
                (3,5.5) .. controls ++(0.8,2)   and ++(-2,-0.1) ..
                (4.5,11).. controls ++(2,0.1)   and ++(-0.2,1.5)..
                (7,6)   .. controls ++(0.2,-1.5)and ++(-0.8,1)  ..
                (8.5,3) .. controls ++(0.8,-1)  and ++(1.8,0.3) ..
                (5.5,2) .. controls ++(-1.8,-.3)and ++(1.5,-.25)..
                (2,0)   .. controls ++(-1.5,.25)and ++(-.25,-1) ..
                (0,2);
    \end{tikzpicture}
\end{document}

如果我有空闲时间,我会完善并完成它,不过还是自己尝试一下吧。

贝塞尔曲线

答案2

一种方便的方法是将您想要跟踪的图形作为环境插入。\node然后您可以添加跟踪图像的路径。(\includegraphicstikzpictureTikzEdthttp://www.tikzedt.org/) 对此特别有用。它有一个贝塞尔绘图工具,当文件tex更改时,绘图会自动重新编译。控件的手柄与网格对齐,因此只需移动这些手柄直到曲线与您要跟踪的曲线匹配就相对容易了。以下是窗口的屏幕截图,TikzEdt显示了带有每条曲线手柄的绘图。

在此处输入图片描述

我通常会手动编辑TikzEdt生成的代码。总共需要 10 分钟。

\documentclass[tikz,border=3pt]{standalone}
\begin{document}

\tikzset{every picture/.append style={line width=2pt,line cap=round}}

\begin{tikzpicture}
%\node at (0,0) {\includegraphics[width=6cm]{Ex240.png}};
%Axes
\draw (-2.7,-2) -- (-1.5,-0.8) -- (-1.5,2)
                   (-1.5,-0.8) -- (-0.3,-0.8) (1.25,-0.8)  -- (2.6,-0.8);
%Hill
\draw[red] (0.7,0.6) .. controls (-0.1,0.4) and (0.2,-0.3) .. 
           (-0.6,-1.3) .. controls (-1.1,-1.4) and (-1,-2.2) .. 
           (0.1,-1.9) .. controls (0.5,-1.6) and (0.7,-1.5) .. 
           (1.5,-1.5) .. controls (1.7,-1.5) and (1.7,-1.3) .. 
           (1.5,-1.3) .. controls (1,-0.9) and (1.4,0.3) .. 
           (0.7,0.6);
\draw[green] (0.7,0.6) .. controls (0.3,0.3) and (0.7,-1.1) .. (-0.3,-1.5);
%Dashed arc
\draw[blue,dashed] (-0.6,-1.3) arc(115:65:2.6);
\end{tikzpicture}

\end{document}

相关内容