palette progression with plotutil.Add*

12 views
Skip to first unread message

Dan Kortschak

unread,
Feb 2, 2014, 5:39:31 PM2/2/14
to plotinum...@googlegroups.com
Hi,

I struck something that I found a little surprising. I had a loop that
did plotutil.AddLinePoints after collecting data. Now when the plot was
rendered all the lines/points were the same colour. I can see why that
happens, the palette is only progressed through when the data sets
series are added as a single collection via the variadic argument. I'm
wondering why this was chosen, rather than picking the colour based on
the length of the []plot.Plotter that is created by that function.

thanks
Dan

Ethan Burns

unread,
Feb 2, 2014, 6:46:34 PM2/2/14
to plotinum...@googlegroups.com
Hi Dan,

I'm not sure that I understand.  Do you mean that you expected each line to have a different color from its corresponding points or something else?  If that is what you are asking, I don't have a particularly good reason.  I tend to make plots where the points have the same color as their lines.  Perhaps there is some argument that it is easier to associate a point with a line of the same color; or maybe one could argue that coloring lines the same as their points requires fewer colors (one color for each <line, point> set instead of one color for each line and a whole new batch of colors for each set of points), but I guess it's mostly a subjective preference.  For now, if you want different colors for lines and their respective points, you will have to do it yourself (its not too hard, but I understand why you'd prefer to just have plotutil behave the way you like).

If you submit a feature request then I'll try to think up an easy and clean way to fit both options into the same interface, but nothing great comes to mind at the moment (I don't like adding a boolean argument to the function, nor do I want to provide two different functions).  Do you have any ideas?


Ethan

Dan Kortschak

unread,
Feb 2, 2014, 6:57:01 PM2/2/14
to Ethan Burns, plotinum...@googlegroups.com
On Sun, 2014-02-02 at 15:46 -0800, Ethan Burns wrote:
> Hi Dan,
>
> I'm not sure that I understand. Do you mean that you expected each line to
> have a different color from its corresponding points or something else? If
> that is what you are asking, I don't have a particularly good reason. I
> tend to make plots where the points have the same color as their lines.

No. The issue is that this (from the wiki):

err = plotutil.AddLinePoints(p,
"First", randomPoints(15),
"Second", randomPoints(15),
"Third", randomPoints(15))
if err != nil {
panic(err)
}

gives a different result to this:

for _, ds := range []struct {
string
plotter.XYs
}{
{"First", randomPoints(15)},
{"Second", randomPoints(15)},
{"Third", randomPoints(15)},
} {
err = plotutil.AddLinePoints(p, ds.string, ds.XYs)
if err != nil {
panic(err)
}
}

The second looks more convoluted, but makes more sense than having to
store temporarily the name and data series until the end of an analysis
and then dump it all to the plot as one variadic argument.

> Perhaps there is some argument that it is easier to associate a point with
> a line of the same color; or maybe one could argue that coloring lines the
> same as their points requires fewer colors (one color for each <line,
> point> set instead of one color for each line and a whole new batch of
> colors for each set of points), but I guess it's mostly a subjective
> preference. For now, if you want different colors for lines and their
> respective points, you will have to do it yourself (its not too hard, but I
> understand why you'd prefer to just have plotutil behave the way you like).
>
> If you submit a feature request then I'll try to think up an easy and clean
> way to fit both options into the same interface, but nothing great comes to
> mind at the moment (I don't like adding a boolean argument to the function,
> nor do I want to provide two different functions). Do you have any ideas?

The change I was thinking of requires that a plot.Plot is able to return
how many series it has already. This may not be something that you want
to add.

>
> Ethan


Ethan Burns

unread,
Feb 2, 2014, 7:10:55 PM2/2/14
to dan.ko...@adelaide.edu.au, plotinum...@googlegroups.com
I see.  That's the intended behavior. But you can do:

var data {}interface
for _, ds := range []struct {
        string
        plotter.XYs
}{
        {"First", randomPoints(15)},
        {"Second", randomPoints(15)},
        {"Third", randomPoints(15)},
} {
  data = append(data, ds.string, ds.XYs)
}
err = plotutil.AddLinePoints(p, data...)
if err != nil {
    panic(err)
}

Though it's slightly uglier.


Ethan

Dan Kortschak

unread,
Feb 2, 2014, 7:14:55 PM2/2/14
to Ethan Burns, plotinum...@googlegroups.com
On Mon, 2014-02-03 at 00:10 +0000, Ethan Burns wrote:
> I see. That's the intended behavior. But you can do:
>
> var data {}interface
> for _, ds := range []struct {
> string
> plotter.XYs
> }{
> {"First", randomPoints(15)},
> {"Second", randomPoints(15)},
> {"Third", randomPoints(15)},
> } {
> data = append(data, ds.string, ds.XYs)
> }
> err = plotutil.AddLinePoints(p, data...)
> if err != nil {
> panic(err)
> }
>
> Though it's slightly uglier.
>
>
> Ethan
>
Yes, that was what I was thinking. Thanks.

Dan

Ethan Burns

unread,
Feb 2, 2014, 7:15:06 PM2/2/14
to plotinum...@googlegroups.com
Oops, I see that you already suggested that approach. Anyway, I don't want to expose the number of plotters on the plot. That is fragile, because not all plotters may be involved in the color theme for your lines and points. For example, if you add a grid or other data before your lines then the colors will change.


Ethan

Reply all
Reply to author
Forward
0 new messages