Why xaxis.ticker throws an error and xaxis.major_tick_label_text_color doesn't?

I am setting some attributes to the xaxis as below:

p.xaxis.major_label_text_color=“orange”
p.xaxis.ticker.desired_num_ticks=1

``


And I get an attribute error for the second line:

     47 p.xaxis.major_label_text_color="orange"
---> 48 p.xaxis.ticker.desired_num_ticks=1
     49

AttributeError: '_list_attr_splat' object has no attribute 'ticker'

I know this can be fixed by applying the ticker property to xaxis[0] instead of xaxis, but I don't understand why the first line works without using list indexing and not the second doesn't? Doing a simple dir(f.xaxis) reveals that both major_label_text_color and ticker are properties of xaxis. Why the discrimination then?



The lists returned by p.axis, etc are referred to as "splattable" lists. They are special list subclasses that behave such that if you set:

  p.xaxis.foo = 10

Then the .foo attr of *every* element in p.xaxis gets set to 10. The reason for making this is, because although there is most often only one x-axis, there *can* be multiple x-axes. So p.xaxis really has to return a list because there may be more than one, and that case has to be accommodated. But it would be really annoying to have to do

  p.xaxis[0].foo = 10

every single time, in the most common case where there is only one axis. So splattable lists are a convenience that saves you from having to do that all the time, every time.

It's pretty nice in most cases, but it does some limitations as you have discovered. In particular, setting attrs can only go "one level deep" which why if you want to set an attribute on a particular ticker of a particular axis, you have to revert to:

  p.xaxis[0].ticker.foo = 10

There's just really no way to extend this "splattable" list concept to go more than one level. E.g. consider:

  p.xaxis.ticker.foo = 10

Naively, the idea would be that that sets the .foo property on every ticker of every x-axis. But not all tickers are the same, what if one is different, and doesn't have a .foo property at all? As I said there is just no clean or sensible way to make things work for more than the "first level" of attrs. Maybe there could be a more meaningful error message somehow, it might be worth a GH issue to discuss.

TLDR; p.xaxis are actually special "splattable" lists, and setting attrs only works "one level deep".

Thanks,

Bryan

···

On Sep 1, 2016, at 11:33 AM, Adi <[email protected]> wrote:

I am setting some attributes to the xaxis as below:

p.xaxis.major_label_text_color="orange"
p.xaxis.ticker.desired_num_ticks=1

And I get an attribute error for the second line:

     47 p.xaxis.major_label_text_color="orange"
---> 48 p.xaxis.ticker.desired_num_ticks=1
     49

AttributeError: '_list_attr_splat' object has no attribute 'ticker'

I know this can be fixed by applying the ticker property to xaxis[0] instead of xaxis, but I don't understand why the first line works without using list indexing and not the second doesn't? Doing a simple dir(f.xaxis) reveals that both major_label_text_color and ticker are properties of xaxis. Why the discrimination then?

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/d1fcf937-ec15-4516-8078-f31266ccf847%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thanks a lot for the thorough explanation!

···

On Thursday, September 1, 2016 at 6:33:24 PM UTC+2, Adi wrote:

I am setting some attributes to the xaxis as below:

p.xaxis.major_label_text_color=“orange”
p.xaxis.ticker.desired_num_ticks=1

``



And I get an attribute error for the second line:


     47 p.xaxis.major_label_text_color="orange"
---> 48 p.xaxis.ticker.desired_num_ticks=1
     49

AttributeError: '_list_attr_splat' object has no attribute 'ticker'


I know this can be fixed by applying the ticker property to xaxis[0] instead of xaxis, but I don't understand why the first line works without using list indexing and not the second doesn't? Doing a simple dir(f.xaxis) reveals that both major_label_text_color and ticker are properties of xaxis. Why the discrimination then?