I'm new to TikZ and pgfplots
but would like to know how to plot the square as well as how to plot the arrows + delta x as well as arrow + delta A:
I'd be most grateful if some of you had some examples I could learn from.
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityI'm new to TikZ and pgfplots
but would like to know how to plot the square as well as how to plot the arrows + delta x as well as arrow + delta A:
I'd be most grateful if some of you had some examples I could learn from.
To answer the specific questions, using TikZ:
To draw curved paths, you can use various methods, described in Section 51.3 Curves of the pgfmanual. Some examples using in=,out=
, bend
and 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}
The dashed rectangle and the arrows for \delta x
can be obtained in a number of ways; for example,
\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}
An here's one possibility for drawing the complete diagram, using the intersections
library:
\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}