[Chicago] Bokeh methods as arguments

Robare, Phillip (TEKSystems) proba at allstate.com
Thu Jun 23 15:00:05 EDT 2016


funcs=[p.circle, p.triangle, ... ] # (13 of them)
for i, xy in enumerate(xys):
    x, y = map(list, zip(*xy))
    color, dash = colors[i], dashes=[i]
    p.line(x, y, color=color, line_dash=dash)
    funcs[i % 13 ](x, y, line_color=color, fill_color='white')

That is, make an array of function pointers and call based on the position of the function in the array.  This will only work if you actually pass exactly the same parameters to each function.  
If you don't you might get the same idea to work using functools.partial to wrap the functions to where you do have all the same parameters.

Phil Robare

-----Original Message-----
From: Chicago [mailto:chicago-bounces+proba=allstate.com at python.org] On Behalf Of Robin Fishbein via Chicago
Sent: Thursday, June 23, 2016 11:44 AM
To: chicago at python.org
Cc: Robin Fishbein <robinfishbein at yahoo.com>
Subject: [Chicago] Bokeh methods as arguments

Is there a way to call methods of the bokeh.plotting.Figure class by passing them as an argument?

I'm trying to write a Bokeh line chart utility that provides pre-selected data point shapes, colors, and line dash styles for a to-be-determined number of data series: a consistent, predefined style that is color-blind-friendly. I can define lists for colors and dashes...
colors = ['blue', 'red', _]
dashes = [[1,0], [2,2], _]
...and pass those values easily because they are keyword arguments, but the shapes are methods of the Figure class.

Here is the behavior I'm trying to copy:

for i, xy in enumerate(xys):
    x, y = map(list, zip(*xy))
    color, dash = colors[i], dashes=[i]
    p.line(x, y, color=color, line_dash=dash)
    if i % 13 == 0:
        p.circle(x, y, line_color=color, fill_color='white')
    elif i % 13 == 1:
        p.triangle(x, y, line_color=color, fill_color='white')
    else:
        pass  # etc.

I'd like to replace the if/elif section with something equivalent to:

    p.myCall(shape_methods[i], x, y, line_color=color, fill_color='white')

Thanks!!
Robin Fishbein
_______________________________________________
Chicago mailing list
Chicago at python.org
https://urldefense.proofpoint.com/v2/url?u=https-3A__mail.python.org_mailman_listinfo_chicago&d=CwICAg&c=gtIjdLs6LnStUpy9cTOW9w&r=VXIryE9UwJGlNMLzgMzDT4_t2NMrZf6alSphHwSEwC0&m=JvCDnJO_NVVkFPvkWQq0G6yr47GFg9Guq5vjsfoeUQ8&s=bbEruqqdpcEp4Qyiy1yY0T5fSUaayd-QSLmrbJAAMVc&e= 


More information about the Chicago mailing list