Let's assume I have the following data. This is exported from LibreOffice as CSV, so I assume this is a correct CSV-format. When I import this CSV into LibreOffice again, I will correctly see the multi-line text in the cell.
Data: MultilineLabels.csv
1,Simple,1.3
2,Single line,2.3
3,"Multiline
label",3.3
4,Simple again,4.3
5,Multiline\nlabel,5.3
6,Simple again,6.3
Now, however, if I want to plot this with the following gnuplot script:
Script:
### How to handle CSV and multi-line labels in gnuplot?
reset session
FILE = "MultilineLabels.csv"
set datafile separator comma
set format x "\n"
plot FILE u 1:3:xtic(2) w lp pt 7 lc "red"
### end of script
I get the following output:
Result:
So, the point and label at x=3
, i.e. line 3 and line 4 of the CSV are not plotted for obvious reasons: gnuplot simply interprets this as text file and has no special CSV input filter.
In principle, I could use some external tools (or maybe even gnuplot itself) to replace all newlines within matching double quotes by \n
.
Would this be the only solution or are there better solutions?
CodePudding user response:
There is no formal standard definition of a CSV file. An empirical formalization of CSV files found in the wild was presented in