gonum/plot: scripting interface ?

123 views
Skip to first unread message

Seb Binet

unread,
May 25, 2016, 1:08:08 PM5/25/16
to gonu...@googlegroups.com
hi there,

you may have seen cznic's plot package that parses a Gnuplot's script file and produces an AST:


Beside the nice twist to be able to produce a plot with gonum/plot using a Gnuplot script file (that'd be nice, wouldn't it?), I was wondering if anybody thought about providing gonum/plot with a scripting interface + an interactive REPL.

As I said in my reply to Jan's post on golang-nuts, I have already the (very very early) beginning of such a thing:

Eventually, I suppose the scripting interface + REPL could be a proper Go interpreter or a Jupyter-based interface (like gophernotes), but in the meantime:

has anybody already tinkered a bit with such an idea?
any ideas about a syntax?
already some code?

(but let's start the discussion, if any, here.)

-s

Brendan Tracey

unread,
May 25, 2016, 1:50:26 PM5/25/16
to Seb Binet, gonu...@googlegroups.com
Exposing such an interface seems like a nice idea. It would be especially great if your work on gonotebok pays off. 

Scripting languages are nice (in this context) for two reasons. First, they store the data after running so you can plot new things you didn’t previously know you wanted to see. Secondly, they typically making quick plots super easy. In matlab, it’s super quick to get a plot using plot(x,y), and maybe with a “hold all” to do some different lines. 

In my personal opinion, we could go a long way to making gonum/plot easier on this second front without having to leave go (or it’s standard compile/run style). This would be done through changing the interfaces and signatures in plotter and plotutil, and possibly adding an “easyplot” package or something for dealing with quick scripts. gonum/plot is great for making nice plots (way better than matlab for changing the way things look), but I haven’t found it to be particularly fun to try and script a bunch of plots.

I know I haven’t contributed much to the development of plot, so sorry if this is just complaining.

Here’s the short list of things I would change:
1) In most of my data, I have a particular set of x values, and several different sets of y values to plot. plotter.XYs is a []struct{X,Y}, so this means that for each data set I have to write code that transforms the {[]float64, []float64} into []struct{X,Y}. It’s not hard, but it’s tedious and I have to do it every time I want to write a plotting script.
2) In addition,  since plotter.XYs is defined as a slice type, it’s annoying to use if you don’t know before hand exactly how many points you’ll need. One has to do something like pts = append(pts, struct{X,Y int}{a,b}). This comes up, for example, if you only want to plot points that meet a certain criteria.
3) The plotutil routines look nice in the examples, but I basically never use them in practice. Frequently I’m writing code that is not plotting a static number of lines. It’s generally easier to add them one by one to the plot (including to the legend), then to try and use plotutil.AddLines (or whatever)

I would love it if I could do
// x []float64, y *mat64.Dense, names []string
p, err := easyplot.Lines(x, y, names)   // added to the legend if names != nil, not otherwise
p.X.Label.Text = “Independent Variable”
p.Y.Label.Text = “Dependent Variable”
_ = p.Save(4*vg.Inch, 4*vg.Inch, “myfile.pdf”)

I feel like this is the idea behind plotutil, but it doesn’t seem to match what I usually want.

Sorry if that was off-topic. Let me know if some of those fixes could match the recent improvements to plot you all have been making, and if I should file issues.


--
You received this message because you are subscribed to the Google Groups "gonum-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gonum-dev+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Dan Kortschak

unread,
May 25, 2016, 5:50:04 PM5/25/16
to Brendan Tracey, Seb Binet, gonum-dev

We're almost six months late on delivering an API stability promise for plot, so I'd like to focus on getting that done before we embark on something of this scale.

Konstantin Shaposhnikov

unread,
May 25, 2016, 10:06:52 PM5/25/16
to gonum-dev, seb....@gmail.com

I know I haven’t contributed much to the development of plot, so sorry if this is just complaining.

Here’s the short list of things I would change:
1) In most of my data, I have a particular set of x values, and several different sets of y values to plot. plotter.XYs is a []struct{X,Y}, so this means that for each data set I have to write code that transforms the {[]float64, []float64} into []struct{X,Y}. It’s not hard, but it’s tedious and I have to do it every time I want to write a plotting script.

I used gonum/plot for the first time a few days ago and also found this a bit cumbersome. I found https://github.com/gonum/plot/issues/146 that proposes to add ZippedXYs type. I think a type like this or even better a func Zip([]float64, []float64) XYer would be quite handy in plotter package.

 
2) In addition,  since plotter.XYs is defined as a slice type, it’s annoying to use if you don’t know before hand exactly how many points you’ll need. One has to do something like pts = append(pts, struct{X,Y int}{a,b}). This comes up, for example, if you only want to plot points that meet a certain criteria.

I agree. Maybe having plotter.XYs defined as

type XY struct {X, Y float64}

type plotter.XYs []XY // instead of anonymous struct

would be more convenient to use (e.g. pts = append(pts, plotter.XY{a,b})) 

 

Seb Binet

unread,
May 30, 2016, 5:34:52 PM5/30/16
to Brendan Tracey, gonu...@googlegroups.com
On Wed, May 25, 2016 at 7:50 PM, Brendan Tracey <tracey....@gmail.com> wrote:
Exposing such an interface seems like a nice idea. It would be especially great if your work on gonotebok pays off. 

Scripting languages are nice (in this context) for two reasons. First, they store the data after running so you can plot new things you didn’t previously know you wanted to see. Secondly, they typically making quick plots super easy. In matlab, it’s super quick to get a plot using plot(x,y), and maybe with a “hold all” to do some different lines. 

In my personal opinion, we could go a long way to making gonum/plot easier on this second front without having to leave go (or it’s standard compile/run style). This would be done through changing the interfaces and signatures in plotter and plotutil, and possibly adding an “easyplot” package or something for dealing with quick scripts. gonum/plot is great for making nice plots (way better than matlab for changing the way things look), but I haven’t found it to be particularly fun to try and script a bunch of plots.

I know I haven’t contributed much to the development of plot, so sorry if this is just complaining.

Here’s the short list of things I would change:
1) In most of my data, I have a particular set of x values, and several different sets of y values to plot. plotter.XYs is a []struct{X,Y}, so this means that for each data set I have to write code that transforms the {[]float64, []float64} into []struct{X,Y}. It’s not hard, but it’s tedious and I have to do it every time I want to write a plotting script.
2) In addition,  since plotter.XYs is defined as a slice type, it’s annoying to use if you don’t know before hand exactly how many points you’ll need. One has to do something like pts = append(pts, struct{X,Y int}{a,b}). This comes up, for example, if you only want to plot points that meet a certain criteria.
3) The plotutil routines look nice in the examples, but I basically never use them in practice. Frequently I’m writing code that is not plotting a static number of lines. It’s generally easier to add them one by one to the plot (including to the legend), then to try and use plotutil.AddLines (or whatever)

I would love it if I could do
// x []float64, y *mat64.Dense, names []string
p, err := easyplot.Lines(x, y, names)   // added to the legend if names != nil, not otherwise
p.X.Label.Text = “Independent Variable”
p.Y.Label.Text = “Dependent Variable”
_ = p.Save(4*vg.Inch, 4*vg.Inch, “myfile.pdf”)

I feel like this is the idea behind plotutil, but it doesn’t seem to match what I usually want.

Sorry if that was off-topic. Let me know if some of those fixes could match the recent improvements to plot you all have been making, and if I should file issues.
yes. please file issues.

I must say I have also felt the pain points 1) and 2).

-s
Reply all
Reply to author
Forward
0 new messages