go-hep / hep

hep is the mono repository holding all of go-hep.org/x/hep packages and tools
https://go-hep.org
BSD 3-Clause "New" or "Revised" License
231 stars 37 forks source link

hplot: consider adding a JSON backend for hplot.Save #986

Closed sbinet closed 1 year ago

sbinet commented 1 year ago

this is a follow-up from https://github.com/go-hep/hep/issues/982.

we could consider adding a JSON backend to hplot.Save, that is:

p := hplot.New()
p.Title.Text = "Title"
p.X.Label.Text = "X"
p.Y.Label.Text = "Y"

err := hplot.Save(p, 10*vg.Centimeter, 20*vg.Centimeter, "plot.json")
if err != nil {
    panic(err)
}
sbinet commented 1 year ago

^^ @mrceyhun

WDYT ? (and the related PR #987)

mrceyhun commented 1 year ago

@sbinet thanks for the heads up.

I tried your PR, it works fine and saves json.

However, my intention is to use JsROOT to draw histogram JSON instead of gonum plot JSON. And JsROOT expects TBufferJSON.ToJSON(hist) kind of JSON, AFAIK. Please consider my limited ROOT knowledge. If there is a possibility to draw this JSON output with JsROOT, it can be useful.

// findObj() just opens the file and returns the ROOT TH1F object
obj := findObj("./dqm.root", "DQMData/Run 366713/EcalPreshower/Run summary/ESRecoSummary/recHits_ES_energyMax")
rh1 := rootcnv.H1D(obj.(rhist.H1))
p := hplot.New()
h := hplot.NewH1D(rh1)
p.Add(h)

err := hplot.Save(p, 10*vg.Centimeter, 20*vg.Centimeter, "plot.json")
if err != nil {
    panic(err)
}

my go.mod:

...
require go-hep.org/x/hep v0.33.0
replace go-hep.org/x/hep v0.33.0 => github.com/sbinet-hep/hep v0.26.1-0.20230905171538-4b6630c113c5
...
sbinet commented 1 year ago

ok, let's track that in https://github.com/go-hep/hep/issues/991

out of curiosity, why do you prefer JsROOT over hplot ? is it b/c of interactivity ? aesthetics ? something else ?

mrceyhun commented 1 year ago

Yes, interactive plots is our users' requirement.

Thanks.