0% found this document useful (0 votes)
70 views5 pages

Manual On Graph and Plot in LaTeX

latex

Uploaded by

dta_shuva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
70 views5 pages

Manual On Graph and Plot in LaTeX

latex

Uploaded by

dta_shuva
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Day 8: Working with Graphs and Plots

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\draw[->] (-3, 0) -- (4.2, 0) node[right] {$x$};
\draw[->] (0, -3) -- (0, 4.2) node[above] {$y$};
\draw[domain=-3:3, variable= \x] plot ({\x}, {\x*\x});
\draw[domain=-3:3,variable= \y] plot ({\y*\y}, {\y});
\end{tikzpicture}
\end{document}

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}[scale=0.45]
\draw[->] (-1,0) -- (10,0) node[below] {$x$};
\draw[->] (0,-1) -- (0,10) node[above] {$y$};
\draw [domain=0.1:10,samples=50] plot (\x,{1/(\x)}) node[right] {$f(x)=\frac{1}{x}$};
\end{tikzpicture}
\end{document}

Pgfplot
The pgfplots package is a powerful tool for graphing in LaTeX. This package is based on tikz
and dedicated to creating scientific graphs. Therefore, Pgfplots is a visualization tool to make
plots in documents. The basic idea is, we provide the input data/formula and pgfplots does the
rest.
The following are the axis option tags []
Axes
xmin=1, xmax=3, ymin=1, ymax=4, width=15cm, height=8cm
xtick={1,2,3}, xticklabels={Step1,Step2,Step3}
axis lines
It changes the way the axes are drawn. default is 'box. Other options are
box, left, middle, center, right, none
Label
xlabel = $x$, ylabel = {$f(x)$},
Grids
grid = major
grid style={dashed, gray!30}
legend pos
\addlegendentry{$x$}
south west, south east, north west, north east, outer north east
mark
It is type of marks used in data plotting. When a single character is used, the character
appearance is very similar to the actual mark. The other options are
*, x , +, |, o, asterisk, star, 10-pointed star, oplus, oplus*, otimes, otimes*, square,
square*, triangle, triangle*, diamond, halfdiamond*, halfsquare*, right*, left*,
Mercedes star, Mercedes star flipped, halfcircle, halfcircle*, pentagon, pentagon*,
cubes. (cubes only work on 3d plots).

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[xmax=9,ymax=9, samples=50]
\addplot[blue, ultra thick] (x,x*x);
\addplot[red, ultra thick] (x*x,x);
\end{axis}
\end{tikzpicture}
\end{document}

\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[]
\addplot[domain=0.1:10]{1/x};
\end{axis}
\end{tikzpicture}
\end{document}
Join Points
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot coordinates{(0,0) (0.5,1) (1,2)};
\end{axis}
\end{tikzpicture}
\end{document}
Plot Graph
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[color=red]{exp(x)};
\end{axis}
\end{tikzpicture}
\end{document}
Plot Graph
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines = left, xlabel = $x$, ylabel = {$f(x)$}]
\addplot[color=red]{exp(x)};
\end{axis}
\end{tikzpicture}
\end{document}
Add Axes
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines = left, xlabel = $x$, ylabel = {$f(x)$}]
\addplot[color=red]{exp(x)};
\end{axis}
\end{tikzpicture}
\end{document}

Add Axes and Domain


\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines = left, xlabel = $x$, ylabel = {$f(x)$}]
\addplot[color=red]{exp(x)};
\end{axis}
\end{tikzpicture}
\end{document}

Add legend
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[axis lines = left, xlabel = $x$, ylabel = {$f(x)$}]
\addplot[domain=-10:10, samples=100, color=red]{x^2 - 2*x - 1};
\addlegendentry[]{$x^2 - 2x - 1$}
\end{axis}
\end{tikzpicture}
\end{document}
Plot trig function
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot[domain=0:360] {sin(x)};
\end{axis}
\end{tikzpicture}
\end{document}
Plot parametric function
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot3[domain=0:15, samples = 60, samples y=0]
({sin(deg(x))},{cos(deg(x))},{x});
\end{axis}
\end{tikzpicture}
\end{document}
Plot surface
\documentclass{article}
\usepackage{tikz}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}
\addplot3[surf]{exp(-x^2-y^2)*x};
\end{axis}
\end{tikzpicture}
\end{document}

You might also like