tikz的一些画图例子
前言
在此记录一些tikz绘制图形的例子,以方便后续使用。
例子1
代码如下:
\documentclass{article} \usepackage{tikz} \begin{document} \usetikzlibrary{intersections} \begin{tikzpicture}[scale=3] %\clip[draw] (-0.8,-0.2) rectangle (1.1,1.75); \draw[->] (-1.5, 0) -- (1.5,0)node [right] {$x$} coordinate (x axis); \draw[->] (0, -1.5) -- (0,1.5)node [above] {$y$} coordinate (y axis); \draw (0,0) circle [radius=1cm]; \draw[step=0.5cm,gray,very thin] (-1.4, -1.4) grid (1.4,1.4) ; \filldraw[fill=green!20!white, draw=green!50!black] (0mm,0mm) -- (3mm,0mm) arc [start angle=0,end angle=30,radius=3mm] -- cycle; \draw (15:2mm) node {\color{green!50!black}$\alpha$}; \draw[red,very thick] (30:1cm) -- node[left=1pt,fill=white]{$\sin\alpha$} (30:1cm |- x axis); \draw[blue,very thick] (30:1cm |- x axis) -- node[below=1pt,fill=white]{$\cos\alpha$} (0,0); \path[name path=upward line] (1,0) -- (1,1); \path[name path=sloped line] (0,0) -- (30:2cm); \draw[name intersections={of=upward line and sloped line, by=x}] [very thick, orange] (1,0) -- node[right=1pt,fill=white]{$\tan\alpha=\frac{\color{red}\sin\alpha}{\color{blue}\cos\alpha}$} (x); \draw (0,0) -- (x); \foreach \x/\xtext in {-1/-1, -0.5/-\frac{1}{2}, 1} \draw (\x cm, 1pt) -- (\x cm, -1pt) node[anchor=north,fill=white] {$\xtext$}; \foreach \y/\ytext in {-1,-0.5/-\frac{1}{2},0.5/\frac{1}{2},1} \draw ( 1pt,\y cm) -- (-1pt, \y cm) node[anchor=east,fill=white] {$\ytext$}; \end{tikzpicture} \end{document}
生成图形如下:
例子2
代码如下:
1 | \documentclass{article} |
生成图形如下:
点击下载源文件
例子3
代码如下:
1 | \documentclass{standalone} |
生成图形如下:
点击下载源文件