我是 TikZ 的新手,pgfplots
但我想知道如何绘制正方形以及如何绘制箭头 + delta x 以及箭头 + delta A:
如果你们能给我提供一些可以学习的例子我将非常感激。
答案1
要回答具体问题,使用 TikZ:
要绘制曲线路径,您可以使用第节中介绍的各种方法。51.3 曲线pgfmanual 中的一些使用
in=,out=
、bend
和 的示例controls=
:\documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \node at (2,2) (a) {A}; \node at (0,0) (b) {B}; \draw[red,->] (a) to[out=0,in=90] (b); \draw[green,->] (a) to[out=180,in=90] (b); \draw[blue,->] (a) to[out=-90,in=0] (b); \node at (4,2) (c) {C}; \node at (2,0) (d) {D}; \draw[olive,->] (c) to[bend right] (d); \draw[cyan,->] (c) to[bend left=90] (d); \node at (7,2) (e) {E}; \node at (5,0) (f) {F}; \draw[magenta,->] (e) to[controls=+(90:1) and +(180:1)] (f); \end{tikzpicture} \end{document}
虚线矩形和箭头
\delta x
可以通过多种方式获得;例如,\documentclass{article} \usepackage{tikz} \begin{document} \begin{tikzpicture} \draw[dashed] (0,0) rectangle (2,3); \node at (4,1.5) (delta) {$\delta x$}; \draw[<-] (delta) -- +(-30pt,0); \draw[<-] (delta) -- +(30pt,0); \end{tikzpicture} \end{document}
以下是使用该库绘制完整图表的一种可能性intersections
:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[scale=0.7,transform shape]
% a macro for the axes, the curve and the two vertical lines
\def\basic{%
\draw[->] (-0.3,0) -- (5,0) node[right] {$x$} coordinate (x axis);
\draw[->] (0,-0.3) -- (0,3) node[above] {$y$};
\draw [name path=curve] (0.5,2) .. controls (1.5,2.8) and (3.5,1) .. (4.5,2);
\path [name path=line 1] (1,0) -- (1,3);
\path [name path=line 2] (4,0) -- (4,3);
\path [name intersections={of=curve and line 1, by={a}}];
\path [name intersections={of=curve and line 2, by={b}}];
\draw (1,0) node[below] {$a$} -- (a);
\draw (4,0) node[below] {$b$} -- (b);
}
% the initial drawing
\basic
\node[above=10pt] at (b) {$y=f(x)$};
% the middle drawing
\begin{scope}[xshift=7cm]
\basic
\path [name path=line 3] (2.5,0) -- (2.5,3);
\path [name path=line 4] (2.8,0) -- (2.8,3);
\path [name path=line 5] (2.2,0) -- (2.2,3);
\fill [name intersections={of=curve and line 3, by={c}}] (c) circle (2pt) node[above right] {$P(x,y)$};
\path [name intersections={of=curve and line 4, by={d}}];
\path [name intersections={of=curve and line 5, by={e}}];
\draw[dashed] (2.5,0) -- (c);
\draw[dashed] (2.8,0) -- (d);
\draw[<->,shorten >=2pt,shorten <= 2pt] (2.2,0) -- node[left] {$y=f(x)$} (e);
\node at (2.65,-0.3) (delta) {$\delta x$};
\draw[<-] (delta) -- +(-20pt,0);
\draw[<-] (delta) -- +(20pt,0);
\end{scope}
% the rightmost drawing
\begin{scope}[xshift=14cm]
\draw[dashed] (0,0) rectangle (0.3,2);
\node at (0.15,-0.3) (delta) {$\delta x$};
\draw[<-] (delta) -- +(-20pt,0);
\draw[<-] (delta) -- +(20pt,0);
\draw[<->,shorten >=2pt,shorten <= 2pt] (-0.3,0) -- node[left] {$y=f(x)$} (-0.3,2);
\node at (1,2.3) (deltaA) {$\delta A$};
\draw[->] (deltaA) to[out=180,in=90] (0.15,1.8);
\end{scope}
\end{tikzpicture}
\end{document}