gonum / plot

A repository for plotting and visualizing data
BSD 3-Clause "New" or "Revised" License
2.72k stars 202 forks source link

Implement vgimg.SvgCanvas #740

Closed jurisbu closed 2 years ago

jurisbu commented 2 years ago

What are you trying to do?

For reasons of symmetry and discover-ability one might want to have vgimg.SvgCanvas.

Canonical example of multi-figure plots via plot.Align uses vgimg.PngCanvas to save "plot". In case user of package wants to save in SVG format there is no easily discover-able path to achieve this goal. One would assume there should exist vgimg.SvgCanvas since there exist vgimg.PngCanvas, vgimg.JpegCanvas and vgimg.TiffCanvas.

What version of Go and Gonum/plot are you using?

    gonum.org/v1/gonum v0.9.3
    gonum.org/v1/plot v0.10.0
sbinet commented 2 years ago

there's already a vgsvg.Canvas:

and vgpdf.Canvas, vgeps.Canvas, vgtex.Canvas and vggio.Canvas.

vgimg holds PngCanvas, JpegCanvas and TiffCanvas because they all work off an image.Image (thus the img in vgimg).

IMHO, vgimg.SvgCanvas wouldn't fit into vgimg.

that said, one could imagine having a set of "hello world" examples of plots for each of the vgxxx backends, available from gonum.org/v1/plot. (also perhaps a few more words about vg, vg/vgxxx backends and the overall architecture of gonum/plot in its top-level documentation)

WDYT?

jurisbu commented 2 years ago

@sbinet Thanks for pointing out where to look into. I will have to look into how to transform plot.Align example to work similar as *plot.Plot.Save() works so that appropriate canvas is used depending on provided file extension.

Just a side note: too many Canvas I guess :smile: My head is spinning, it is rather hard to figure out as an outsider and a humble package user. I can see how it works quite well for authors of package that know ins and outs.

sbinet commented 2 years ago

you'd just have to replace:

img := vgimg.New(vg.Points(150), vg.Points(175))

with:

svg := vgsvg.New(vg.Points(150), vg.Points(175))

and, further down:

if _, err := png.WriteTo(w); err != nil {

with:

if _, err := svg.WriteTo(w); err != nil {