使用 Tikz 绘制图片

使用 Tikz 绘制图片

我正在尝试绘制如下函数图: 在此处输入图片描述

不知道如何开始。有人能帮我看看这张图片吗?

答案1

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{patterns}
\begin{document}
\begin{tikzpicture}[scale=pi]
\draw[thick,-latex] (-2,0) -- (2,0) node[below left]{$S$};
\draw[thick,-latex] (0,0) -- (0,2);
\draw[thick,pattern=north east lines] (-1,1) parabola[bend pos=0.5] bend +(0,-0.5) +(2,0) 
-- (0,0) -- cycle;
\draw[thick] (-1.5,1.5) -- (0,0) -- (1.5,1.5);
\foreach \X in {-1,1}
{\draw (\X,0.05) -- (\X,-0.05) node[below]{$\X$};}
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

如果有人对 TikZ 的替代品感兴趣,这里有一个版本元帖子. 用 编译lualatex

在此处输入图片描述

\documentclass[border=5mm]{standalone}
\usepackage{luatex85}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
    % unit space
    numeric u;
    u = 16mm;

    % define the paths we need
    path xx, yy, rays, curve, area;
    xx = (left--right) scaled 2.2u;
    yy = origin -- up scaled 2.2u;

    rays = ((-2,2) -- origin -- (2,2)) scaled u;
    curve = ((-1,1) .. (0, sqrt(2)/2) {right} .. (1,1)) scaled u;

    % find the enclosed area -- buildcycle works better 
    % if the paths are running "in the same direction"
    area = buildcycle(rays, reverse curve);

    % draw some hatching and then clip them to the enclosed area
    for t = -2u step 1/16 u until 2u:
        draw yy rotated -30 shifted (t,0) 
            withpen pencircle scaled 1/4
            dashed evenly scaled 1/4
            withcolor 3/4 blue;
    endfor
    clip currentpicture to area;

    % draw the paths
    draw curve withcolor 2/3 blue;
    draw rays;
    drawarrow xx;
    drawarrow yy;

    % add some labels
    for t=-1, 1:
        draw (down--up) shifted (t*u,0);
        label.bot("$" & decimal t & "$", (t*u,0));
    endfor
    label.rt("$S$", point 1 of xx);

endfig;
\end{mplibcode}
\end{document}

相关内容