您的位置:首页 > 其它

pgfplots画二维图真的很方便,多例比较

2016-06-15 20:58 281 查看
%直接PDFLATEX编译即可
\documentclass[border=1mm]{standalone}
\usepackage{tkz-euclide,pgfplots}
\begin{document}
\begin{tikzpicture}[domain=0:4]
\tkzInit[xmax=4.2,ymax=4.2,xmin=-1.2,ymin=-3.2,xstep=1]
\tkzGrid
\tkzAxeXY
\draw[color=red] plot (\x,\x) node[right] {$f(x)=x$};
\draw[color=orange,domain=-0.5:4] plot (\x,{0.05*exp(\x)}) node[right] {$f(x)=\frac{1}{20}\mathrm e^x$};
\draw[color=blue,domain=0:4] plot (\x,{sin(\x r)}) node[right] {$f(x)=\sin x$};
\draw[color=blue!50,x=1cm,y=0.5cm,domain=-0.5:2.4] plot (\x, {(\x)^3-4*(\x)+2}) node[right] {$f(x)=x^3-4x+2$};
\end{tikzpicture}
\end{document}

%直接PDFLATEX编译即可
\documentclass[border=1mm]{standalone}
\usepackage{tkz-euclide,pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[x=.5cm,xmin=0,ymin=0]
\addplot[mark=none,smooth,red,thick] expression[domain=0:12]{exp(((x-6)^2)/(-9))};
\addplot[mark=none,smooth,blue,thick] expression[domain=1:19]{exp(((x-10)^2)/(-25))};
\addplot[mark=none,smooth,ultra thick] expression[domain=7.5:12]{exp(((x-6)^2)/(-9))};
\addplot[mark=none,smooth,ultra thick] expression[domain=1:7.5]{exp(((x-10)^2)/(-25))};
\addplot[dotted,mark=none]coordinates{(6,0)(6,1)};
\addplot[dotted,mark=none]coordinates{(10,0)(10,1)(0,1)};
\addplot[dashed,mark=none]coordinates{(7.5,0)(7.5,0.7788)(0,0.7788)};
\node[pin=-45:{$P$}] at (axis cs:0,0.7788) {};
\node[pin=135:{$P_x$}] at (axis cs:7.5,0) {};
\end{axis}
\end{tikzpicture}
\end{document}

%直接PDFLATEX编译即可
\documentclass[border=1mm]{standalone}
\usepackage{tkz-euclide,pgfplots}
\begin{document}
\begin{tikzpicture}[domain=0:4]
\draw[very thin,color=gray] (-0.1,-1.1) grid (3.9,3.9);
\draw[->,>=angle 90] (-0.2,0) -- (4.2,0) node[right] {$x$};
\draw[->,>=angle 90] (0,-1.2) -- (0,4.2) node[above] {$f(x)$};
%plot选项请看pgfmanual手册第224页
\draw[color=red] plot (\x,\x) node[right] {$f(x)=x$};
\draw[color=orange] plot (\x,{0.05*exp(\x)}) node[right] {$f(x)=\frac{1}{20}\mathrm e^x$};
%下面的sin函数,要注意弧度和度数单位的转换,手册第225页
\draw[color=blue] plot (\x,{sin(\x r)}) node[right] {$f(x)=\sin x$};
\draw[color=blue,x=1cm,y=0.5cm,domain=-0.5:2.4] plot (\x, {(\x)^3-4*(\x)+2}) node[right] {$f(x)=x^3-4x+2$};
\end{tikzpicture}
\end{document}

from: http://blog.sina.com.cn/s/blog_01ea595801013ig7.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: