查看原文
其他

LaTeX 绘图轻松入门(第二集)

BowerC LaTeX工作室 2024-04-20

我们来分享如何在直角坐标系(极坐标)中绘制基本函数图像,本次分享内容主要包括:多项式函数、幂函数、指数函数、对数函数、三角函数,反三角函数以及极坐标函数对应的函数图像。所有案例代码,请放在以下代码环境中运行:

\documentclass%[border=5mm]
{standalone}
\usepackage{etex}
\usepackage{tikz,times}
\usepackage{pgfplots}
\usepgfplotslibrary{polar,colormaps,colorbrewer}
\pgfplotsset{compat=1.16}
\usetikzlibrary{calc,decorations.markings}
\usepackage{amssymb,amsmath,pgfornament,shapepar}
\usetikzlibrary{calc,positioning,intersections}
\usetikzlibrary{arrows}
\newsavebox{\bbox}
\usetikzlibrary{shapes.geometric,through,decorations.pathmorphing, arrows.meta,quotes,mindmap,shapes.symbols,shapes.arrows,automata,angles,3d,trees,shadows,automata,arrows,
shapes.callouts}

\definecolor{db}{rgb}{0.12,0.53,1}
\definecolor{Beige}{rgb}{0.9,0.9,0.9}
\usetikzlibrary{patterns,scopes,math}
\definecolor{mycolor}{RGB}{167,174,245}
\definecolor{redid}{RGB}{248,150,208}
\newcommand{\bd}{\boldsymbol}
\usepackage[hidelinks]{hyperref}
\begin{document}
%% your code
\end{document}

一、基本函数

(一)符号函数

符号函数表达为: f(x)=sgnx

\begin{tikzpicture}
\draw[-Stealth](-1.25,0)--(0,0)node[below left]{$O$}--(1.25,0)node[below]{$x$};
\draw[-Stealth](0,-1.25)--(0,1.25)node[left]{$y$};
\draw(0,0.5)--(1.2,0.5)(0,-0.5)--(-1.2,-0.5);
\filldraw[fill=white](0,0.5)circle(0.5pt)(0,-0.5)circle(0.5pt);
\node[left]at(0,0.5){$1$};\node[right]at(0,-0.5){$-1$};
\fill(0,0)circle(0.5pt);\node at(-1,0.6){$y=\operatorname{sgn}x$};
\end{tikzpicture}

\begin{tikzpicture}
\draw[-Stealth](-1.25,0)--(0,0)node[below left]{$O$}--(1.25,0)node[below]{$x$};
\draw[-Stealth](0,-1.25)--(0,1.25)node[left]{$y$};
\draw(0,-0.5)--(1.2,-0.5)(0,0.5)--(-1.2,0.5);
\filldraw[fill=white](0,0.5)circle(0.5pt)(0,-0.5)circle(0.5pt);
\node[left]at(0,-0.5){$1$};\node[right]at(0,0.5){$-1$};
\fill(0,0)circle(0.5pt);\node at(1.5,0.6){$y=-\operatorname{sgn}x$};
\end{tikzpicture}
符号函数图像

(二)取整函数

取整函数 f(x)=[x]

\begin{tikzpicture}[scale=0.5]
\draw[-Stealth](-5,0)--(0,0)node[below left]{$O$}--(5.2,0)node[below]{$x$};
\draw[-Stealth](0,-5)--(0,5)node[left]{$y$};
\foreach \x in{-4,-3,...,4}
{\draw(\x,\x)--(\x+1,\x);\draw(\x,0)--(\x,0.05)(0,\x)--(0.05,\x);
\fill(\x,\x)circle(1pt);\draw[white](1,0)--(1,0.05);}
\foreach \x in{-4,-3,...,4}
\filldraw[fill=white](\x+1,\x)circle(1pt);
\foreach \x in{-4,-3,-2,-1,1,2,3,4}
{\node[below]at(\x,0){$\x$};}
\foreach \x in{1,2,3,4}
\node[left]at(0,\x){$\x$};
\foreach \x in{-2,-3,-4}
\node[left]at(0,\x){$\x$};
\node[below left]at(0,-1){$-1$};\node at(-2,2){$y=[x]$};
\end{tikzpicture}
取整函数图像

(三)幂函数

形如 f(x)=xα 的函数:

\begin{tikzpicture}[samples=100]
\draw[-Stealth](-4,0)--(0,0)node[below right]{$O$}--(4,0)node[below]{$x$};
\draw[-Stealth](0,-4)--(0,4)node[left]{$y$};
\draw[domain=-1.6:1.6]plot(\x,{(\x)^3})node[right]{$y=x^3$};
\draw[densely dashed,domain=-1.6:1.6]plot({(\x)^3},\x)node[below]{$y=\sqrt[3]x$};
\draw[semithick,domain=0:1.9]plot({(\x)^2},\x)node[above]{$y=\sqrt x$};
\draw[thick,domain=-3.2:3.2]plot(\x,\x)node[right]{$y=x$};
\draw[domain=0.26:3.7]plot(\x,{1/(\x)});
\draw[domain=-0.26:-3.7]plot(\x,{1/(\x)});
\node(a)at(1.5,-1.5){$y=\frac1x$};
\draw[-Stealth](a.west)--(-0.6,-1.5);
\draw[-Stealth](a.north)--(1.5,0.6);
\draw[semithick,domain=-1.85:1.85]plot(\x,{(\x)^2});
\node at(-1.85,3.6){$y=x^2$};
\end{tikzpicture}
幂函数图像

(四)指数函数和对数函数

形如 f(x)=αx 的函数图像:

\begin{tikzpicture}[samples=100]
\draw[-Stealth](-4,0)--(0,0)node[below left]{$O$}--(4,0)node[below]{$x$};
\draw[-Stealth](0,-4)--(0,4)node[left]{$y$};
\draw[domain=-3.7:1.8]plot(\x,{2^(\x)})node[right]{$y=2^x$};
\draw[domain=3.7:-1.8]plot(\x,{2^(-\x)})node[left]{$y=\left(\frac12\right)^x$};
\node at(-0.3,1){$1$};\node at(1,-0.3){$1$};
\draw[domain=-3.7:1.8]plot({2^(\x)},\x)node[above]{$y=\log_2x$};
\draw[domain=3.7:-1.8]plot({2^(-\x)},\x)node[below]{$y=\log_{\frac12}x$};
\end{tikzpicture}
img

指数函数与对数函数图像

二、三角函数

(一)正弦函数及反函数

函数 f(x)=sin⁡x 及 f(x)=arcsin⁡x 的函数图像:

\begin{tikzpicture}[samples=100,scale=1.4]
\draw[-Stealth](-3.2,0)--(0,0)node[below right]{$O$}--(3.2,0)node[below]{$x$};
\draw[-Stealth](0,-2)--(0,2)node[left]{$y$};
\draw[domain=-pi:pi]plot(\x,{sin(\x r)});
\draw[semithick,domain=-pi/2:pi/2]plot({sin(\x r)},\x);
\node at(1.9,1.2){$y=\sin x$};\node at(1.3,1.7){$y=\arcsin x$};
\draw[densely dashed](1,pi/2)--(1,0)node[below]{$1$}
(1,pi/2)--(0,pi/2)node[left]{$\frac\pi2$};
\draw[densely dashed](-1,-pi/2)--(-1,0)node[above]{$-1$}
(-1,-pi/2)--(0,-pi/2)node[right]{$-\frac\pi2$};
\end{tikzpicture}
正弦函数及其反函数图像

正弦函数图像几何意义

\begin{tikzpicture}
\foreach \iangle in {45,80,120,150}{
\fill[fill=orange!60!red,fill opacity=0.2](0,0) -- (0:2) arc (0:\iangle:2) -- cycle;
\filldraw[fill=green!40!black,fill opacity=0.5](0,0) --(0:0.3) arc (0:\iangle:0.3) -- cycle;
  \draw[->] (-2.2,0) -- (2.2,0);
  \draw[->] (0,-2.2) -- (0,2.2);
  \draw[thick,draw=green!40!black] (0,0) circle (2);
  \coordinate[label=\iangle:$P$] (P) at (\iangle:2);
  \coordinate[label=below:$P_0$] (P0) at (P |- 0,0);
  \draw (0,0) -- (P);
  \draw (P) -- (P0);
  \draw[->] (5,0) -- (11,0);
  \draw[->] (0,-2.2) -- (0,2.2);
        \draw[->] (2*pi,-2.2) -- (2*pi,2.2);
\draw[thick,domain=4:10,smooth,draw=green!40!black] plot(\x,{2*sin(\x r)}) node[right] {$\sin x$};
\foreach \t in {0,30,90} {
   \draw ({rad(\t)},-0.05) -- ({rad(\t)},0.05);
   \node[below,outer sep=2pt,fill=white,font=\tiny]
   at ({rad(\t)},0) {\ang{\t}};}
\foreach \y in {-1,1} {\draw (-0.05,\y) -- (0.05,\y); }
  \coordinate[label=above:$Q$] (Q) at ({rad(\iangle+360)},{2*sin(\iangle+360)});
  \coordinate[label=below:$Q_0$] (Q0) at (Q |- 0,0);
  \draw (Q) -- (Q0);
  \draw[dashed] (P) -- (Q);
}
\end{tikzpicture}
正弦函数图像几何意义

(二)余弦函数

函数 f(x)=cos⁡x 和 f(x)=arccos⁡x 的函数图像

\begin{tikzpicture}[samples=100]
\draw[-Stealth](-2.5,0)--(0,0)node[below right]{$O$}--(5.5,0)node[below]{$x$};
\draw[-Stealth](0,-1.2)--(0,3.5)node[left]{$y$};
\draw[domain=-pi/2:3*pi/2]plot(\x,{cos(\x r)});\node at(1.4,1.4){$y=\arccos x$};
\draw[semithick,domain=0:pi]plot({cos(\x r)},\x);
\node at(1.9,0.6){$y=\cos x$};
\node[left]at(0,1.2){$1$};\
\node[below] at(-pi/2,0){$-\frac\pi2$};
\node[below]at(pi/2,0){$\frac\pi2$};
\node[below]at(1,0){$1$};\node[right]at(0,1.63){$\frac\pi2$};
\node[below]at(3*pi/2,0){$\frac32\pi$};
\fill(-1,pi)circle(0.8pt)node[above]{$(-1,\pi)$};
\end{tikzpicture}
余弦函数及其反函数图像

余弦函数的几何意义

\begin{tikzpicture}
\foreach \iangle in {45,90,120}{
\fill[fill=blue!40!black,fill opacity=0.2](0,0) -- (0:2) arc (0:\iangle:2) -- cycle;
\filldraw[fill=orange!60!red,fill opacity=0.5](0,0) --(0:0.3) arc (0:\iangle:0.3) -- cycle;
  \draw[->] (-2.2,0) -- (3.5,0);
  \draw[->] (0,-2.2) -- (0,2.2);
  \draw[thick,draw=orange!60!red] (0,0) circle (2);
  \coordinate[label=\iangle:$P$] (P) at (\iangle:2);
  \coordinate[label=below:$P_0$] (P0) at (P |- 0,0);
  \draw (0,0) -- (P);
  \draw (P) -- (P0);
  \draw[->] (4,0) -- (11,0);
  \draw[->] (0,-2.2) -- (0,2.2);
        \draw[->] (2*pi,-2.2) -- (2*pi,2.2);
\draw[thick,domain=4:10.6,smooth,draw=orange!60!red] plot(\x,{2*cos(\x r)}) node[right] {$\cos x$};
  \foreach \t in {0,90,180} {
  \draw ({rad(\t)},-0.05) -- ({rad(\t)},0.05);
  \node[below,outer sep=2pt,fill=white,font=\tiny]
   at ({rad(\t)},0) {\ang{\t}};}
  \foreach \y in {-1,1} {\draw (-0.05,\y) -- (0.05,\y);}
  \coordinate[label=above:$Q$] (Q) at ({rad(\iangle+270)},{2*cos(\iangle+270)});
  \coordinate[label=below:$Q_0$] (Q0) at (Q |- 0,0);
  \draw (Q) -- (Q0);
  \draw[dashed] (P) -- (Q);
}
\end{tikzpicture}
余弦函数的几何意义

(三)正切函数

函数 f(x)=tan⁡x 和函数 f(x)=arctan⁡x 函数图像

\begin{tikzpicture}[samples=100,scale=0.9]
\draw[-Stealth](-5.5,0)--(0,0)node[below right]{$O$}--(5.5,0)node[below]{$x$};
\draw[-Stealth](0,-3)--(0,3)node[left]{$y$};
\draw[domain=-4.3:-2]plot(\x,{tan(\x r)});
\draw[dashed](-3*pi/2,-2.4)--(-3*pi/2,2.4);
\draw[dashed](-pi/2,-2.4)--(-pi/2,2.4);
\draw[dashed](pi/2,-2.4)--(pi/2,2.4);
\draw[dashed](3*pi/2,-2.4)--(3*pi/2,2.4);
\draw[domain=-1.16:1.16]plot(\x,{tan(\x r)});
\draw[domain=2:4.3]plot(\x,{tan(\x r)});
\node[below left]at(-3*pi/2,0){$-\frac32\pi$};
\node[below left]at(3*pi/2,0){$\frac32\pi$};
\node[below left]at(pi/2,0){$\frac\pi2$};\node[below left]at(-pi/2,0){$-\frac\pi2$};
\node[below]at(pi,0){$\pi$};\node[below]at(-pi,0){$-\pi$};
\node(a)at(1.6,2.8){$y=\tan x$};\node(b) at(2.8,2){$y=\arctan x$};
\draw[semithick,domain=-1.35:1.35]plot({tan(\x r)},\x);
\draw[dashed](-5,pi/2)--(5,pi/2)(-5,-pi/2)--(5,-pi/2);
\draw[-Stealth](2.8,1.87)--(2.8,1.25);
\draw[-Stealth](1.6,2.65)--(-1.95,2.1);
\draw[-Stealth](1.6,2.65)--(1.19,2.1);\draw[-Stealth](1.6,2.65)--(4.2,2.1);
\end{tikzpicture}
正弦函数及反函数图像

正切函数的几何意义

\begin{tikzpicture}
\foreach \iangle in {45}{
   \fill[fill=blue!40!black,fill opacity=0.2]
   (0,0) -- (0:1) arc (0:\iangle+14:1) -- cycle;
   \filldraw[fill=orange!60!red,fill opacity=0.5]
   (0,0) --(0:0.3) arc (0:\iangle+14:0.3) -- cycle;
   \draw[->] (-1.2,0) -- (2,0);
            \draw[->] (2.5,0) -- (5,0);
      \draw[->] (0,-2.2) -- (0,2.2);
            \draw[thick,dashed] (1,-2.2) -- (1,2.2);
            \draw[->] (pi,-2.2) -- (pi,2.2);
   \draw[thick,draw=orange!60!red] (0,0) circle (1);
   \coordinate[label=\iangle:$P$] (P) at (1,{tan(\iangle r)});
            \coordinate[label=above:$Q$] (Q) at ({rad(\iangle+193)},{tan(\iangle+193)});
      \coordinate[label=below:$Q_0$] (Q0) at (Q |- 0,0);
      \draw (Q) -- (Q0);
      \draw[dashed] (P) -- (Q);
   \draw (0,0) -- (P);
   \draw[thick,domain=0.65*pi:1.35*pi,smooth,draw=orange!60!red] plot(\x,{tan(\x r)}) node[right] {$\tan x$};
%% ==========================================================  
  \foreach \t in {0,90} {
   \draw ({rad(\t)},-0.05) -- ({rad(\t)},0.05);
   \node[below,outer sep=2pt,fill=white,font=\tiny]
   at ({rad(\t)},0) {\ang{\t}}; 
  }
  \foreach \y in {-1,1} {
   \draw (-0.05,\y) -- (0.05,\y);
  }
}
 \end{tikzpicture}
正切函数的几何意义

三、极坐标函数图像

(一)圆的极坐标函数

圆 r=2acosθ 的图像:

\begin{tikzpicture}[samples=100]
\draw[-Stealth](-1,0)--(0,0)node[below left]{$O$}--(3,0)node[below]{$x$};
\draw[-Stealth](0,-1.5)--(0,1.5)node[left]{$y$};
\draw plot[tension=1,smooth cycle]coordinates{(0,0)(1,1)(2,0)(1,-1)};
\node [below]at(2.2,0){$2a$};\node [below]at(1,0){$a$};
\fill(1,0)circle(0.5pt);
\node at(1.1,-1.2){$r=2a\cos\theta$};
\node at(1.3,1.2){$x^2+y^2=2ax$};
\end{tikzpicture}
圆的极坐标图像

(二)椭圆极坐图像

椭圆 x2a2+y2b2=1 极坐标图像

\begin{tikzpicture}[samples=200]
\draw[-Stealth](-2,0)--(0,0)node[below left]{$O$}--(2,0)node[below]{$x$};
\draw[-Stealth](0,-1.5)--(0,1.5)node[left]{$y$};
\draw[domain=0:2*pi]plot({1.414*cos(\x r)},{sin(\x r)});
\node[left=-1pt] at(0,1.2){$b$};\node[left=-1pt] at(0,-1.2){$-b$};
\node[below] at(-1.63,0){$-a$};\node[below] at(1.5,0){$a$};
\node at(1.1,1.3){$\frac{x^2}{a^2}+\frac{y^2}{b^2}=1$};
\node[align=flush center] at(1.1,-1.3){$x=a\cos\theta$\\[-2mm]
$y=a\sin\theta$};
\end{tikzpicture}
椭圆的图像

(三)其他极坐标图像

\begin{tikzpicture}[samples=200]
\draw[-Stealth](-2,0)--(2,0)node[below]{$x$};
\draw[-Stealth](0,-1.5)--(0,1.5)node[left]{$y$};
\draw[domain=-pi/4:pi/4]plot({1.414*sqrt(cos(2*\x r))*cos(\x r)},{1.414*sqrt(cos(2*\x r))*sin(\x r)})--(0,0);
\draw[domain=-pi/4:pi/4,rotate=180]plot({1.414*sqrt(cos(2*\x r))*cos(\x r)},{1.414*sqrt(cos(2*\x r))*sin(\x r)})--(0,0);
\node at(-4pt,-9pt){$O$};
\node[below]at(-1.63,0){$-a$};\node[below]at(1.5,0){$a$};
\node at(0,0.8){$(x^2+y^2)^2=a^2(x^2-y^2)$};
\node at(0.7,-0.8){$r^2=a^2\cos2\theta$};
\end{tikzpicture}
\begin{tikzpicture}[scale=0.8]
\draw[-Stealth](0,0)--(7.2,0)node[below]{$x$};
\draw[-Stealth](0,0)--(0,3)node[left]{$y$};
\node[below left]at(0,0){$O$};
\draw[domain=0:8,samples=200]plot({\x-sin(\x r)},{1-cos(\x r)});
\node[below]at(6.28,0){$2\pi a$};
\draw[densely dashed](0,2)--(7.2,2);
\draw[densely dash dot](-0.3,1)--(7.2,1)(3.1415,0)--(3.1415,2.1)(0.83,-0.2)--(0.83,2.17);
\node[below=2pt]at(3.1415,0){$\pi a$};
\draw (0.83,1)circle(1cm);
\draw[-{Stealth[width=0pt 5]}](0.83,1)--(0.3,1.87);
\node at (0.4,1.4){$a$};
\draw[-{Stealth[width=0pt 5]}](0.83,1)--(0.1,0.32);
\fill(0.1,0.32)circle(1pt);
\draw[-{Stealth[width=0pt 6]}](0.83,0.4)arc(-90:-138:0.6);
\node at(0.7,0.64){$\theta$};
\node[align=center] at(4,2.6){$x=a(\theta-\sin\theta)$\\[-2mm]
$y=a(1-\cos\theta)$};
\end{tikzpicture}
案例1
\begin{tikzpicture}[samples=200]
\draw[-Stealth](-1.5,0)--(2.5,0)node[below]{$x$};
\draw[-Stealth](0,-1.5)--(0,1.5)node[left]{$y$};
\draw[domain=0:2*pi]plot({(cos(\x r))^3},{(sin(\x r))^3});
\node[left]at(0,1){$a$};\node[left]at(0,-1){$-a$};
\node[below]at(1,0){$a$};\node[below]at(-1,0){$-a$};
\node at(1.5,0.6){$x^{\frac23}+y^{\frac23}=a^{\frac23}$};
\node[align=center]at(1.4,-0.9){$x=a\cos^3\theta$\\[-2mm]$y=a\sin^3\theta$};
\node at(-5pt,-5pt){$O$};
\end{tikzpicture}
\begin{tikzpicture}[samples=200]
\draw[-Stealth](-0.5,0)--(2.5,0)node[below]{$x$};
\draw[-Stealth](0,-1.5)--(0,1.5)node[left]{$y$};
\draw[domain=-pi:pi]plot({1.6*cos(\x/2 r)*cos(\x r)},{1.6*cos(\x/2 r)*sin(\x r)});
\node at(-5pt,-5pt){$O$};\node[below]at(1.8,0){$2a$};
\node at(1.5,-1.4){$r=a(1+\cos\theta)$};
\end{tikzpicture}
\begin{tikzpicture}[samples=200]
\draw[-Stealth](-1.5,0)--(1.5,0)node[below]{$x$};
\draw[-Stealth](0,-0.5)--(0,2.2)node[left]{$y$};
\draw[domain=-pi:pi,rotate=90]plot({1.6*cos(\x/2 r)*cos(\x r)},{1.6*cos(\x/2 r)*sin(\x r)});
\node at(-5pt,5pt){$O$};\node[left=-2pt]at(0,1.75){$2a$};
\node at(1.5,-1.4){$r=a(1+\cos\theta)$};
\node at(0,-0.7){$r=a(1+\sin\theta)$};
\end{tikzpicture}
例2

参考资料

  1. TikZpgf manual
  2. 向老师的 tikz 绘图笔记二 - LaTeX 工作室

关注我们公众号,学习 LaTeX 无烦恼!

入门资料,免费知识代码:

https://flowus.cn/latex/share/66110e84-b24a-4cd5-b8a7-2ba2afb35a30

精心制作免费视频教程:

https://space.bilibili.com/209746320

抖音课程

继续滑动看下一个
向上滑动看下一个

您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存