Rafael Villarroel

Home Page

Simple Pgfplots Examples

| Comments

Only one graph

01
1
2
3
4
5
\begin{tikzpicture}[scale=0.7]
  \begin{axis}
    \addplot {x^2};
   \end{axis}
\end{tikzpicture}

Setting the domain

02
1
2
3
4
5
\begin{tikzpicture}[scale=0.7]
  \begin{axis}
    \addplot[domain=-4:4] {x^2};
  \end{axis}
\end{tikzpicture}

Two graphs, one with attributes

03
1
2
3
4
5
6
\begin{tikzpicture}[scale=0.7]
  \begin{axis}
    \addplot[domain=-4:4,red,very thick] {x^2};
    \addplot {x};
  \end{axis}
\end{tikzpicture}

Labels to the plot

04
1
2
3
4
5
\begin{tikzpicture}[scale=0.7]
  \begin{axis}[title=A plot,xlabel={\(x\)},ylabel={\(x^{2}\)}]
    \addplot[domain=-4:4,red,very thick] {x^2};
  \end{axis}
\end{tikzpicture}

05
1
2
3
4
5
6
7
\begin{tikzpicture}[scale=0.7]
  \begin{axis}[title=A plot,xlabel={\(x\)},ylabel={\(x^{2}\)},
    legend entries={\(\alpha\),\(\beta\)}]
    \addplot[domain=-4:4,red,very thick] {x^2};
    \addplot[domain=-4:4,blue,very thick] {x};
  \end{axis}
\end{tikzpicture}

06
1
2
3
4
5
6
7
\begin{tikzpicture}[scale=0.7]
  \begin{axis}[title=A plot,xlabel={\(x\)},ylabel={\(x^{2}\)},
    legend entries={\(\alpha\),\(\beta\)},grid=major]
    \addplot[domain=-4:4,red,very thick] {x^2};
    \addplot[domain=-4:4,blue,very thick] {x};
  \end{axis}
\end{tikzpicture}

07
1
2
3
4
5
6
7
8
\begin{tikzpicture}[scale=0.7]
  \begin{axis}[legend entries={\(\alpha\),\(\beta\)},grid=major]
    \addplot[domain=-4:4,red,very thick] {x^2};
    \addplot[domain=-4:4,blue,very thick] {x};
    \node at (2,2) {Hi};
    \draw[cyan,line width=5pt] (-2,2) -- (0,10);
  \end{axis}
\end{tikzpicture}

08
1
2
3
4
5
6
7
8
9
\begin{tikzpicture}[scale=0.7]
  \begin{axis}[legend entries={\(\alpha\),\(\beta\)},grid=major]
    \addplot[domain=-4:4,red,very thick] {x^2};
    \addplot[domain=-4:4,blue,very thick] {x};
    \draw[fill=magenta] (2,2) circle (3pt);
    \node at (2,1) {\tiny Hi};
    \node at (2,0) {\large Hello};
  \end{axis}
\end{tikzpicture}

Same scale on both axis, with axis equal image.

09
1
2
3
4
5
6
\begin{tikzpicture}[scale=0.7]
  \begin{axis}[axis equal image]
    \addplot[domain=-4:4,red,very thick] {x^2};
    \addplot[domain=-4:4,blue,very thick] {x};
  \end{axis}
\end{tikzpicture}

Nice axis, with axis lines=middle.

10
1
2
3
4
5
6
\begin{tikzpicture}[scale=0.7]
  \begin{axis}[axis lines=middle]
    \addplot[domain=-4:4,red,very thick] {x^2-2};
    \addplot[domain=-4:4,blue,very thick] {x};
  \end{axis}
\end{tikzpicture}

Comments