[Tex/LaTex] the best way to plot coordinates in Latex

plot

I need to plot some points in a graph; just a simple list of x and y values and then connect them with line segments. Currently, I am graphing it in excel and importing the image into latex and it doesn't look good. Is there any way to plot coordinates just using latex?

Best Answer

Data points can be directly entered using the data command from the datavisualization library. The same applies if you have the function instead of the data points. Here are some examples adapted from the TikZ-PGF manual:

\documentclass[border=2mm,tikz]{standalone}
\usetikzlibrary{datavisualization}
\begin{document}

\begin{tikzpicture}
\datavisualization [school book axes, visualize as smooth line]
    data {
       x, y
    -1.5, 2.25
      -1, 1
     -.5, .25
       0, 0
      .5, .25
       1, 1
     1.5, 2.25
    };
\end{tikzpicture}

\end{document}

enter image description here

Changing the axes style to scientific, e.g., can give a different look:

\datavisualization [scientific axes, all axes={grid}, visualize as smooth line]

enter image description here

Also, if you have the function at hand, this can be quite easy:

\documentclass[border=2mm,tikz]{standalone}
\usetikzlibrary{datavisualization.formats.functions}
\begin{document}

\begin{tikzpicture}
  \datavisualization [school book axes, visualize as smooth line]
    data [format=function] {
      var x : interval [-1.5:1.5] samples 7;
      func y = \value x*\value x;
    };
\end{tikzpicture}

\end{document}

with the same result as the data points entry:

enter image description here

Related Question