0

I am trying to create a simple time series plot of daily price data using pgfplots. My data file is in CSV format and in the same folder as my working Tex file.

The data file has header titles in each of the top cells (Date and Price). All I need to do is plot the Closing Price on the y axis vs the time in the x axis. The time is in the form: 2010.542466, 2010.545205,... etc for daily price data. The code I have tried thus far in Latex looks like this:

\pgfplotstableread[col sep = comma]{coindesk.csv}

\begin{tikzpicture}
\begin{axis}[
xlabel=t,
ylabel=Close]
\addplot table[x=t,y=Close] {coindesk.csv};
\end{axis}
\end{tikzpicture}

However I get a series of error messages. Any help would be appreciated.

EDIT: The first three lines of my data look like:

t   Close 
2010.542466 0.09
2010.545205 0.08
2010.547945 0.07
  • 1
    Hi, welcome. First of all, when using \pgfplotstableread you need to specify a macroname to save the table to, e.g. \pgfplotstableread{filename.dat}\mydata. But you don't need to use \pgfplotstableread as you've added the filename directly in your \addplot. So then you might need col sep=comma there. Does that help? If not, which errors do you get exactly? And can you add the first three lines of your data file exactly like they appear in the file? – Torbjørn T. Mar 13 '17 at 21:30
  • The errors I get look like this: Package pgfplots Error: Could not read table file 'coindesk.csv' in 'search phe pgfplotstable manual for details). \addplot table[x=t,y=Close] {coindesk.csv}; the current plot has no coordinates (or all have been filtered away) You have an axis with empty range (in direction y). Replacing it with a default range and clearing all plots. – K Upadhyay Mar 13 '17 at 21:38
  • Where is the .csv file relative to your .tex file? Same folder, or different folder? – Torbjørn T. Mar 13 '17 at 21:39
  • It's in the same folder – K Upadhyay Mar 13 '17 at 21:41
  • I've started getting new errors: Package pgfplots Error: Sorry, the requested column number '' in table 'coindesk.csv' does not exist!? Please verify you used the correct index 0 <= i < N.. \addplot table[x=t,y=Close] {coindesk.csv}; – K Upadhyay Mar 13 '17 at 21:45
1

There is no comma in your .csv file. If you add comma to your data file, the command \addplot table[col sep=comma] {coindesk.csv}; should work.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.