使用 Tikz 绘制不规则图形

使用 Tikz 绘制不规则图形

我正在尝试使用 tikz 绘制这些图形,但看起来不规则,我不知道该怎么做。我几乎可以做所有事情,除了红色的不规则图形,我需要帮助。任何帮助都将不胜感激。谢谢。

在此处输入图片描述

\documentclass{article}
\usetikzlibrary{shapes.geometric}
\usetikzlibrary{shapes, decorations, shadows}  
\usetikzlibrary{decorations.pathmorphing}  
\usetikzlibrary{decorations.shapes}
\usetikzlibrary{chains,arrows,positioning,decorations.pathreplacing}  
\usetikzlibrary{fadings}  
\usetikzlibrary{patterns}  
\usetikzlibrary{calc,fit}

\begin{document}

\begin{tikzpicture}
\begin{axis}[width=15cm,compat=1.5,height=9.5cm,
axis y line=center,
axis x line=middle,
xmin=-5,xmax=5,
ymin=-5,ymax=5,
xlabel=$x$,ylabel=$y$,
anchor=center
]
%\addplot[smooth,very thick,mark size=1.5pt,color=red,mark=*] plot coordinates 
{(0,0) (1,-1) (4,-2)}; % node[right] {$y=\sqrt{x}$};

\addplot+[-latex', >=latex,color=red,smooth,very 
thick,mark=none,samples=200,unbounded coords=jump] {sqrt(x)};
\end{axis}
\end{tikzpicture}

\end{document}

答案1

不幸的是,这个问题对我来说不是很清楚,所以这个答案是基于猜测并提供所需的图像。这意味着,你的 MWE 不是很有帮助。从中我只看到,你期望图形由pgfplots而不是纯粹的tikz...绘制。

看看我的结果是否符合你的要求:

在此处输入图片描述

上面的图像是通过以下代码完成的:

\documentclass[border=3mm]{standalone}
\usepackage{pgfplots}
    \pgfplotsset{width=6cm, compat=1.13,
                 title style={at={(0.5,-0.1)}, anchor=north, font=\large},
                 xlabel style = {anchor=west},
                 ylabel style = {anchor=south},
                 clip=false
                  }% <-- common styles 
    \usetikzlibrary{arrows}

\begin{document}
    \begin{tikzpicture}
\begin{axis}[%small,anchor=aninnernode.center,
axis y line=center,
axis x line=middle,
%
xmin=-0.5,xmax=5,
ymin=-0.5,ymax=5,
xtick={0}, ytick={0},% this disables the standard
ylabel=$y$,
xlabel=$x$,
title = {$f$ is increasing},
]
\addplot[line width=2pt,red,%
         domain=0.5:4.5, samples=9, mark=none,
         ->] {0.2*(x^2) + 1};
\node[right] at (4.5,{0.2*(4.5^2) + 1})  {$f(x)$};
%
\draw[dashed]   (0,{0.2*(2^2) + 1}) node[left] {$f(x_1)$}  -|
                (2, 0)              node[below] {$x_1$}
                (0,{0.2*(3^2) + 1}) node[left] {$f(x_2)$}  -|
                (3, 0)              node[below] {$x_2$};
\end{axis}
    \end{tikzpicture}
\hfill
    \begin{tikzpicture}
\begin{axis}[%small,anchor=aninnernode.center,
axis y line=center,
axis x line=middle,
%
xmin=-0.5,xmax=5,
ymin=-0.5,ymax=5,
xtick={0}, ytick={0},% this disables the standard
ylabel=$y$,
xlabel=$x$,
title = {$f$ is decreasing},
]
\addplot[line width=2pt,red,%
         domain=0.5:4.5, samples=9, mark=none,
         ->] {7-3*sqrt(x)};
\node[right] at (4.5,{7-3*sqrt(4.5)})  {$f(x)$};
%
\draw[dashed]   (0,{7-3*sqrt(2)})   node[left] {$f(x_1)$}  -|
                (2, 0)              node[below] {$x_1$}
                (0,{7-3*sqrt(3)})   node[left] {$f(x_2)$}  -|
                (3, 0)              node[below] {$x_2$};
\end{axis}
    \end{tikzpicture}
\end{document}

该代码(几乎)是半解释性的,但如果您对此有任何疑问,请提出。

附录: 纯 TikZ 解决方案的代码似乎稍微简单一些:

\documentclass[border=3mm]{standalone}
\usepackage{tikz}

\begin{document}
    \begin{tikzpicture}[domain=0.5:4.5, samples=17,]
% axes                        
\draw[->] (-0.5,0) -- node[below=5mm] {$f$ is increasing}
                      + (5.5,0) node[right] {$x$};
\draw[->] (0,-0.5) -- + (0,5.5) node[above] {$y$};
% graph
\draw[line width=2pt, draw=red, ->] 
    plot (\x,{0.2*(\x^2) + 1}) node[right] {$f(x)$};
%
\draw[dashed]   (0,{0.2*(2^2) + 1}) node[left]  {$f(x_1)$}  -|
                (2, 0)              node[below] {$x_1$}
                (0,{0.2*(3^2) + 1}) node[left]  {$f(x_2)$}  -|
                (3, 0)              node[below] {$x_2$};
    \end{tikzpicture}
\hfill
    \begin{tikzpicture}[domain=0.5:4.5, samples=17]
% axes
\draw[->] (-0.5,0) -- node[below=5mm] {$f$ id decreasing}
                      + (5.5,0) node[right] {$x$};
\draw[->] (0,-0.5) -- + (0,5.5) node[above] {$y$};
% graph
\draw[line width=2pt, draw=red, ->] 
    plot (\x,{7-3*sqrt(\x)}) node[right]  {$f(x)$};
%
\draw[dashed]   (0,{7-3*sqrt(2)})   node[left] {$f(x_1)$}  -|
                (2, 0)              node[below] {$x_1$}
                (0,{7-3*sqrt(3)})   node[left] {$f(x_2)$}  -|
                (3, 0)              node[below] {$x_2$};
    \end{tikzpicture}
\end{document}

上述 MWE 的结果与第一个解决方案(使用pgfplots)的结果(几乎)相同

相关内容