On Saturday, September 11, 2021 10:30:25 PM IST Hans Hagen wrote: > On 9/11/2021 4:27 PM, kauśika cittūr via ntg-context wrote: > > Dear All, > > > > I am truly grateful for the new additions to MetaFun. It has greatly > > helped me in producing neat drawings for my academic work. In this > > connection, I have a few queries. > > > > Currently I am using PGFPlots (with ConTeXt) to draw simple plots from CSV > > data. I was wondering if there is any way to do the same in MetaFuns. That > > is, is it possible to do something like the following in order to obtain > > a line plot of the values in the 'data.csv' file? Also is it possible to > > have the 'labels' be the identical for all points in a given list? > > > > \startMPcode > > > > draw lmt_axis [ > > > > sx = 2mm, sy = 2mm, > > nx = 80, ny = 40, > > tx = 15, ty = 15, > > > > list = { > > > > [ > > > > connect = true, > > color = "darkblue", > > close = true, > > points = {data.csv}, > > labels = {"•"}, > > > > ] > > > > }, > > > > ] withpen pencircle scaled 0.5mm; > > > > \stopMPcode > > It depends on how one has data in the csv, You can patch mlib-scn.lmt > (line 659) > > if type(v) == "table" then > return injectpath(v,connector,close) > elseif type(v) == "string" then > local code = load("return " .. v) > if code then > return code() > end > else > return injectpair(0,0) > end > > then a string represents a function: > > \starttext > > \startluacode > io.savedata("temp.csv", "x,y\n10,10\n20,40\n30,30\n") > > local mycsvsplitter = utilities.parsers.rfc4180splitter() > > function MP.MyPoints(name) > local data = io.loaddata(name) > local list = mycsvsplitter(data) > table.remove(list,1) > for i=1,#list do > list[i][1] = tonumber(list[i][1]) > list[i][2] = tonumber(list[i][2]) > end > mp.inject.path(list) > end > > \stopluacode > > \startMPcode > draw lmt_axis [ > sx = 2mm, sy = 2mm, > nx = 80, ny = 40, > tx = 15, ty = 15, > > list = { > [ > connect = true, > color = "darkblue", > close = true, > points = "MP.MyPoints('temp.csv')", > labels = {"•"}, > ] > }, > ] withpen pencircle scaled 0.5mm; > \stopMPcode > > \stoptext > > we can of course have some predefined and when we can agree on how these > files loo, adding a "csv" is no big deal ... it's all about consistent > interfacing > > > ----------------------------------------------------------------- > Hans Hagen | PRAGMA ADE > Ridderstraat 27 | 8061 GH Hasselt | The Netherlands > tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl > -----------------------------------------------------------------
Dear Hans, Many thanks for your detailed guidance. I think for now this patch should suffice for my simple needs. Best, kauśika ___________________________________________________________________________________ If your question is of interest to others as well, please add an entry to the Wiki! maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context webpage : http://www.pragma-ade.nl / http://context.aanhet.net archive : https://bitbucket.org/phg/context-mirror/commits/ wiki : http://contextgarden.net ___________________________________________________________________________________