Possibly 3 bugs ? Plotting interface color styling

Hi everyone !

I would like to scatter points with different colors and alphas. I read

http://bokeh.pydata.org/en/latest/docs/user_guide/styling.html

And it says:

Colors properties are used in many places in Bokeh, to specify the colors to use for lines, fills or text. Color values can be provided in any of the following ways:

  • any of the 147 named CSS colors, e.g 'green', 'indigo'
  • an RGB(A) hex value, e.g., '#FF0000', '#44444444'
  • a 3-tuple of integers (r,g,b) between 0 and 255
  • a 4-tuple of (r,g,b,a) where r, g, b are integers between 0 and 255 and a is a floating point value between 0 and 1
    and I am not sure if I found some bugs or whether I just don’t get the documentation above or I am confusing something …Having some initial code :

TOOLS=“resize,crosshair,pan,wheel_zoom,box_zoom,reset,tap,previewsave,box_select,poly_select,lasso_select”

output_file(“color_scatter.html”, title=“color_scatter.py example”)

p = figure(tools=TOOLS)

Now some experiments :

----- ----- ----- ----- 1st problem ----- ----- ----- ----- ----- ----- ----- Can’t specify alpha in hexadecimal format

p.scatter([1,2,3], [1,2,3], radius=[0.05,0.1,0.2], fill_color=“red”, fill_alpha=0.6, line_color=“Black”)

show(p) # all good, red points as expected with alpha 0.6

p.scatter([1,2,3], [1,2,3], radius=[0.05,0.1,0.2], fill_color=“FF00000077”, line_color=“Black”)

show # now I thought I would get transparent red points by specifiing alpha to bde 0x77 but all points are just white.

Therefore I am ble to do this :

p.scatter([1,2,3], [1,2,3], radius=[0.05,0.1,0.2], fill_color=["#44FF4455", “#FF0000”, “#00FF00”], line_color=“Black”)

but not this

p.scatter([1,2,3], [1,2,3], radius=[0.05,0.1,0.2], fill_color=["#44FF4455", “#FF000088”, “#00FF00AA”], line_color=“Black”)

----- ----- ----- ----- 2nd problem ----- ----- ----- ----- ----- ----- ----- Can’t specify alpha in hexadecimal format

p.scatter([1,2,3], [1,2,3], radius=[0.05,0.1,0.2], fill_color=(0,255,255), line_color=“Black”);

show( p ) # works ok, skyblue scatter points

p.scatter([1,2,3], [1,2,3], radius=[0.05,0.1,0.2], fill_color=(0,255,255,255), line_color=“Black”);

show( p ) # adding the additional alpha this way completely breaks everything and nothing gets displayed at all

----- ----- ----- ----- 3rd problem ----- ----- ----- ----- ----- ----- ----- Can’t specify array of for colors in list/tupple format

p.scatter([1,2,3], [1,2,3], radius=[0.05,0.1,0.2], fill_color=[‘blue’,‘green’,‘red’], line_color=“Black”);

show( p ) # everything as expected, 3 points, different colors

p.scatter([1,2,3], [1,2,3], radius=[0.05,0.1,0.2], fill_color=[(0,0,255),(0,255,0),(255,0,0)], line_color=“Black”)

show ( p ) # I get just 3 white points

p.scatter([1,2,3], [1,2,3], radius=[0.05,0.1,0.2], fill_color=[[0,0,255],[0,255,0],[255,0,0]], line_color=“Black”)

show ( p ) # I get just 3 white points

Thank you for insights and comments in forward !!

I did some recent work on color alpha, so I took a look. The thing I focused on was adding support for rgba tuples, but it looks like rgba hex wasn’t implemented on the python side either.

Some potential things that could be done on the bokeh side:

  • improve errors so that there is better feedback inside of _glyph_functions.py, function _match_data_params. If color inputs don’t match any of the checks, it ends up throwing an error about no matching column name.

  • add rgba hex, which should be rather easy…the tests would likely be the biggest part

  • potentially support lists of ColorSpecs, instead of a single ColorSpec, as it appears is currently supported

On your use of bokeh, here are some observations:

  • Your examples are using (a, r, g, b), instead of (r, g, b, a), where (0…255, 0…255, 0…255, 0…1). I’m confident this works, as I created the example you see in the docs, with the source being available here.

  • On a quick look, I don’t see a specific place saying scatter would take multiple color values in that way. There are some glyphs that do, but almost all examples show coloring the entire group of glyphs the same color. You might be able to do this with columndatasource, as seen here: http://bokeh.pydata.org/en/latest/docs/gallery/iris.html. My recommendation though would be to iterate over the things that are of different colors, then plot those separately, where x and y are arrays/lists, but radius/color are singular. It is likely the way you tried is intended to work, but currently the code that handles the color inputs doesn’t correctly identify those as such. This definitely works:

for group, color, radius in zip(groups, colors, radii):
p.scatter(group.x, group.y, radius=radius, color=color)
show(p)

``

Handling all of the potential combinations of inputs can get pretty complex, so I’d defer to someone else for intended functionality. For example, in your example you are using a single line_color, but an array of fill_color. For my version of bokeh, I don’t even get white points for your last examples, it errors out on me, which appears to be due to “Black”, instead of “black”.

p.scatter([1, 2, 3], [1, 2, 3], radius=[0.05, 0.1, 0.2], fill_color=(0, 0, 255, 0.5), line_color=“black”)

show(p)

``

···

On Tuesday, July 14, 2015 at 8:33:17 PM UTC-5, Patrik Stas wrote:

Hi everyone !

I would like to scatter points with different colors and alphas. I read

http://bokeh.pydata.org/en/latest/docs/user_guide/styling.html

And it says:

Colors properties are used in many places in Bokeh, to specify the colors to use for lines, fills or text. Color values can be provided in any of the following ways:

  • any of the 147 named CSS colors, e.g 'green', 'indigo'
  • an RGB(A) hex value, e.g., '#FF0000', '#44444444'
  • a 3-tuple of integers (r,g,b) between 0 and 255
  • a 4-tuple of (r,g,b,a) where r, g, b are integers between 0 and 255 and a is a floating point value between 0 and 1
    and I am not sure if I found some bugs or whether I just don’t get the documentation above or I am confusing something …Having some initial code :

TOOLS=“resize,crosshair,pan,wheel_zoom,box_zoom,reset,tap,previewsave,box_select,poly_select,lasso_select”

output_file(“color_scatter.html”, title=“color_scatter.py example”)

p = figure(tools=TOOLS)

Now some experiments :

----- ----- ----- ----- 1st problem ----- ----- ----- ----- ----- ----- ----- Can’t specify alpha in hexadecimal format

p.scatter([1,2,3], [1,2,3], radius=[0.05,0.1,0.2], fill_color=“red”, fill_alpha=0.6, line_color=“Black”)

show(p) # all good, red points as expected with alpha 0.6

p.scatter([1,2,3], [1,2,3], radius=[0.05,0.1,0.2], fill_color=“FF00000077”, line_color=“Black”)

show # now I thought I would get transparent red points by specifiing alpha to bde 0x77 but all points are just white.

Therefore I am ble to do this :

p.scatter([1,2,3], [1,2,3], radius=[0.05,0.1,0.2], fill_color=[“#44FF4455”, “#FF0000”, “#00FF00”], line_color=“Black”)

but not this

p.scatter([1,2,3], [1,2,3], radius=[0.05,0.1,0.2], fill_color=[“#44FF4455”, “#FF000088”, “#00FF00AA”], line_color=“Black”)

----- ----- ----- ----- 2nd problem ----- ----- ----- ----- ----- ----- ----- Can’t specify alpha in hexadecimal format

p.scatter([1,2,3], [1,2,3], radius=[0.05,0.1,0.2], fill_color=(0,255,255), line_color=“Black”);

show( p ) # works ok, skyblue scatter points

p.scatter([1,2,3], [1,2,3], radius=[0.05,0.1,0.2], fill_color=(0,255,255,255), line_color=“Black”);

show( p ) # adding the additional alpha this way completely breaks everything and nothing gets displayed at all

----- ----- ----- ----- 3rd problem ----- ----- ----- ----- ----- ----- ----- Can’t specify array of for colors in list/tupple format

p.scatter([1,2,3], [1,2,3], radius=[0.05,0.1,0.2], fill_color=[‘blue’,‘green’,‘red’], line_color=“Black”);

show( p ) # everything as expected, 3 points, different colors

p.scatter([1,2,3], [1,2,3], radius=[0.05,0.1,0.2], fill_color=[(0,0,255),(0,255,0),(255,0,0)], line_color=“Black”)

show ( p ) # I get just 3 white points

p.scatter([1,2,3], [1,2,3], radius=[0.05,0.1,0.2], fill_color=[[0,0,255],[0,255,0],[255,0,0]], line_color=“Black”)

show ( p ) # I get just 3 white points

Thank you for insights and comments in forward !!