#CSV Read in cetz-plot

2 messages · Page 1 of 1 (latest)

proud vapor
#

#csv() imports the csv as an array of strings, how do I convert this so that I can plot with cetz-plot?
cetz-plot uses a parameter 'value-key' to designate which items to use from the CSV. I think map(int) should be applied to each item somehow?

example showing array defined chart in blue and csv defined chart in red (currently throws an error because it can't do anything with the strings)

#import "@preview/cetz:0.2.2": canvas, draw, plot, chart, palette

#set page(width: auto, height: auto, margin: .5cm)

#let data = (
            (1,2,3,4,5,6),
            (1,2,3,4,5,6),
            (5,1,0,1,2,3),
            (4,6,2,1,2,3),
            (4,6,2,1,2,2),
            (4,6,2,1,2,3),
            (1,3,1,1,2,0),
            )

#let colchart = canvas({
  draw.set-style(legend: (fill: white))
  chart.columnchart(
                 data,
                 mode: "clustered",
                 size: (6, 3),
                 bar-style:palette.blue,
                 value-key: (..range(0, 6)),
                 )
})

#colchart
*\#let data = *
#data

#v(10pt)

#let csvdata = csv("test.csv")

#let colchart2 = canvas({
  draw.set-style(legend: (fill: white))
  chart.columnchart(
                //
                 csvdata,
                 mode: "clustered",
                 size: (6, 3),
                 bar-style:palette.red,
                 value-key: (..range(0, 6)),
                 )
})

#colchart2
*csv("test.csv")* = 
#csvdata
proud vapor
#

Maybe it would be easiest to create an array to hold the CSV data and convert it in the process?