3

Is it possible to plot data of the following sort in LaTeX?

enter image description here

Since the data is huge, sourcing it from an external file would be desired, but not necessary.

  • 1
    The answer to this question shows, how to plot data from a CSV file using the pgfplots package. Does this work for you? – hbaderts Jul 28 '16 at 13:05
  • It doesn't for two reasons. 1. Formatting and 2. The data is not actually coming from an external file. It just names the dataset data.csv, following with the actual data inside LaTeX. –  Jul 28 '16 at 13:08
  • 1
    @RussianSoyuzRocket: 2. The data is actually coming from an external file. The way the filecontents environment works is that when the LaTeX file is run it writes to data.csv the text that's included in the environment, and then runs the rest of the compilation with data.csv as an external file. It is basically an implementation of tar for LaTeX. – Willie Wong Jul 28 '16 at 13:32
  • 1
    Exactly, just remove the whole \begin{filecontents} ... \end{filecontents} stuff and replace data.csv in the \addplot command by your actual file name. – hbaderts Jul 28 '16 at 13:35
  • About the formatting: could you edit your question to include the code for the plot you have now, and show/tell us what exactly you want to have different? – hbaderts Jul 28 '16 at 13:37
  • 1
    In terms of formatting: you've shown us an example output. It looks like you want to do a smooth line plot with no markers. To remove the markers you pass the option mark=none and to make it a smooth instead of a piecewise linear plot, pass the option smooth. See section 4 of the pgfplots manual. – Willie Wong Jul 28 '16 at 13:40
  • This worked like a charm. @WillieWong, I'd appreciate if you can post both your comments as an answer so I can mark them as accepted and vote them up. –  Jul 28 '16 at 13:42

2 Answers2

4

The following worked like a charm for me, as stated by Willie Wong:

Include the following packages:

\usepackage{pgfplots}

and use the following for the figure:

\begin{tikzpicture}
\includegraphics[width=\textwidth,height=4cm]{tiger}
\begin{axis}
\addplot table [x=a, y=b, col sep=comma, mark=none, smooth] {pilot.csv};
\end{axis}
\end{tikzpicture}
F1iX
  • 358
3

[Converted from comments]

The general template for loading data from a csv file is as in this answer: you can just remove the portion enclosed in \begin{filecontents}... \end{filecontents} and replace the filename data.csv by your actual `csvc file.

To get the style indicated in the question, you likely want to use \addplot+[smooth,mark=none] to get smoothly interpolated curve with no markers. For more customization of your plot, you can refer to the pgfplots manual.

Willie Wong
  • 24,733
  • 8
  • 74
  • 106