I would like to read in data from a CSV file into a plot. Unfortunately, the data contains commas itself:
Name, Description, Data
hello, "hello, world", 1
Note that the data is quoted using quotation marks, which is quite common when it comes to CSV files. I read in the file using the following:
\pgfplotstableread[col sep=comma]{data.csv}{\datatable}
Problem is: the pgfplotstable
package does not seem to be able to handle quotes, specifically, I get an error message because there are apparently too many entries in the second row. I edited the file in the following way:
Name, Description, Data
hello, hello\, world, 1
This seems to work OK. I then tried to use the Description
column as symbolic coordinates in a plot:
\begin{axis}[yticklabels from table={\datatable}{Description}]
# ....
\end{axis}
Problem in this case: the commas disappear, the label only reads "hello world".
Is there a way to read the quoted entries (I am stuck using pgfplotstable
), or to quote the file in such a way that I can read the column into the labels?
hello, {hello, world}, 1
would work. Note that\,
is a LaTeX macro for a small horizontal space, not a quoted comma, which would explain why your test did not produce a comma.pgfplotstable
. at tex.stackexchange.com/questions/375737/…, changing"Grapes", 22
to"{Grapes, red}", 22
and it works fine with the grouped comma. Without the grouping braces, it errs just as in your case.\let\comma,
and then in your data set usehello, hello\comma{} world, 1
, but this seems more difficult than the group approach. Note though, that with the group approach, evenhello, hello{,} world, 1
would be sufficient.