pdfplts原创
基于tikz
可绘制2D、3D图像的宏包。
# 设置
\pgfplotsset{width=7cm} %设置宽度
\usepgfplotslibrary{polar, colormaps} % polar 极坐标; colormaps 颜色
# 实例
# 实例1 3D
点击查看
\documentclass[dvisvgm]{standalone} %生成使用dvisvgm生成SVG,需要配合standalone(文档类使用)
\usepackage{amsmath} %导言区调用amsmath宏包 用于数学符号
\usepackage{tikz} %导言区调用tikz宏包
\usepackage{pgfplots} % 使用 pgfplots 画函数图更方便,可以绘制 2D 3D 图像
\newcommand{\num}{pi}
\pgfplotsset{compat=1.8}
% define the plot style and the axis style
\tikzset{elegant/.style={smooth,thick,samples=50,magenta}}
\usetikzlibrary{patterns}
\begin{tikzpicture}
\begin{axis}[
title=Example using the mesh parameter,
hide axis,
colormap/cool,
]
\addplot3[
mesh,
samples=50,
domain=-8:8,
]
{sin(deg(sqrt(x^2+y^2)))/sqrt(x^2+y^2)};
\addlegendentry{\(\frac{sin(r)}{r}\)}
\end{axis}
\end{tikzpicture}
\end{document}
# 三角函数
# tan cot
点击查看
\documentclass[dvisvgm]{standalone} %生成使用dvisvgm生成SVG,需要配合standalone(文档类使用)
\usepackage{amsmath} %导言区调用amsmath宏包 用于数学符号
\usepackage{tikz} %导言区调用tikz宏包
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{tikzpicture}[scale=1.5]
\begin{axis}[
axis lines=middle,
axis line style={thick,<->},
xmin=-2*pi-0.5,xmax=2*pi+0.5,ymin=-1.5,ymax=1.5,
ytick={-1,1},
xtick={-2*pi,-1.5*pi,-pi,-0.5*pi,0,0.5*pi,pi,1.5*pi,2*pi},
xticklabels={$-2\pi$,$-\frac{3}{2}\pi$,$-\pi$,$-\frac{1}{2}\pi$,$0$,$+\frac{1}{2}\pi$,$+\pi$,$+\frac{3}{2}\pi$,$+2\pi$},
tick label style={font=\tiny},
grid=major,
major grid style={dashed,very thin,black},
every axis plot post/.append style={thick},
label style={font=\tiny},
xlabel=$x$,
ylabel=$y$,
smooth,
%clip=false,restrict y to domain=-4:4,
legend style={
font=\tiny,
legend cell align=left,
legend pos=outer north east,
draw=none,
empty legend},
legend entries={[blue]$y=\sin x$,[red]$y=\cos x$}]
\addplot[domain=-2*pi:2*pi,samples=200,blue]{sin(deg(x))};
\addplot[domain=-2*pi:2*pi,samples=200,red]{cos(deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}
# tan cot
点击查看
\documentclass[dvisvgm]{standalone} %生成使用dvisvgm生成SVG,需要配合standalone(文档类使用)
\usepackage{amsmath} %导言区调用amsmath宏包 用于数学符号
\usepackage{tikz} %导言区调用tikz宏包
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{tikzpicture}[scale=1.5]
\begin{axis}[
axis lines=middle,
axis line style={thick,<->},
xmin=-2*pi-0.5,xmax=2*pi+0.5,ymin=-4.5,ymax=4.5,
ytick={-4,-3,-2,-1,1,2,3,4},
xtick={-2*pi,-1.5*pi,-pi,-0.5*pi,0,0.5*pi,pi,1.5*pi,2*pi},
xticklabels={$-2\pi$,$-\frac{3}{2}\pi$,$-\pi$,$-\frac{1}{2}\pi$,$0$,$+\frac{1}{2}\pi$,$+\pi$,$+\frac{3}{2}\pi$,$+2\pi$},
tick label style={font=\tiny},
grid=major,
major grid style={dashed,very thin,black},
every axis plot post/.append style={thick},
label style={font=\tiny},
xlabel=$x$,
ylabel=$y$,
smooth,
%clip=false,restrict y to domain=-4:4,
legend style={
font=\tiny,
legend cell align=left,
legend pos=outer north east,
draw=none,
empty legend},
legend entries={[red]$y=\tan x$,[blue]$y=\cot x$}]
\addplot[domain=-2 *pi:-1.5*pi,samples=200,red]{tan(deg(x))};
\addplot[domain=-1.5*pi:-0.5*pi,samples=200,red]{tan(deg(x))};
\addplot[domain=-0.5*pi: 0.5*pi,samples=200,red]{tan(deg(x))};
\addplot[domain= 0.5*pi: 1.5*pi,samples=200,red]{tan(deg(x))};
\addplot[domain= 1.5*pi: 2 *pi,samples=200,red]{tan(deg(x))};
\addplot[domain=-2 *pi: -pi,samples=200,blue]{cot(deg(x))};
\addplot[domain= -pi: 0,samples=200,blue]{cot(deg(x))};
\addplot[domain= 0: pi,samples=200,blue]{cot(deg(x))};
\addplot[domain= pi: 2*pi,samples=200,blue]{cot(deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}
# sec csc
点击查看
\documentclass[dvisvgm]{standalone} %生成使用dvisvgm生成SVG,需要配合standalone(文档类使用)
\usepackage{amsmath} %导言区调用amsmath宏包 用于数学符号
\usepackage{tikz} %导言区调用tikz宏包
\usepackage{pgfplots}
\pgfplotsset{compat=1.8}
\begin{document}
\begin{tikzpicture}[scale = 1.5]
\begin{axis}[
axis lines=middle,
axis line style={thick,<->},
xmin=-2*pi-0.5,xmax=2*pi+0.5,ymin=-4.5,ymax=4.5,
ytick={-4,-3,-2,-1,1,2,3,4},
xtick={-2*pi,-1.5*pi,-pi,-0.5*pi,0,0.5*pi,pi,1.5*pi,2*pi},
xticklabels={$-2\pi$,$-\frac{3}{2}\pi$,$-\pi$,$-\frac{1}{2}\pi$,$0$,$+\frac{1}{2}\pi$,$+\pi$,$+\frac{3}{2}\pi$,$+2\pi$},
tick label style={font=\tiny},
label style={font=\tiny},
grid=major,
major grid style={dashed,very thin,black},
every axis plot post/.append style={semithick},
xlabel=$x$,
ylabel=$y$,
smooth,
%clip=false,restrict y to domain=-4:4,
legend style={
font=\tiny,
legend cell align=left,
legend pos=outer north east,
draw=none,
empty legend},
legend entries={[blue]$y=\csc x$,[red]$y=\sec x$}
]
\addplot[domain=-2 *pi: -pi,samples=200,blue]{cosec(deg(x))};
\addplot[domain= -pi: 0,samples=200,blue]{cosec(deg(x))};
\addplot[domain= 0: pi,samples=200,blue]{cosec(deg(x))};
\addplot[domain= pi: 2*pi,samples=200,blue]{cosec(deg(x))};
\addplot[domain=-2 *pi:-1.5*pi,samples=200,red]{sec(deg(x))};
\addplot[domain=-1.5*pi:-0.5*pi,samples=200,red]{sec(deg(x))};
\addplot[domain=-0.5*pi: 0.5*pi,samples=200,red]{sec(deg(x))};
\addplot[domain= 0.5*pi: 1.5*pi,samples=200,red]{sec(deg(x))};
\addplot[domain= 1.5*pi: 2 *pi,samples=200,red]{sec(deg(x))};
\end{axis}
\end{tikzpicture}
\end{document}
上次更新: 2022/08/23, 18:12:45