Repository: bokeh/bokeh

Issue:
Global alpha for image_rgba plot
It's currently not possible to set a global alpha for image_rgba plots. 

Example code:

```
import numpy as np
from bokeh.plotting import figure, show, output_file

N = 20
img = np.empty((N, N), dtype=np.uint32)
view = img.view(dtype=np.uint8).reshape((N, N, 4))
for i in range(N):
    for j in range(N):
        view[i, j, 0] = int(i/N*255)
        view[i, j, 1] = 158
        view[i, j, 2] = int(j/N*255)
        view[i, j, 3] = 255

p = figure(x_range=(0, 10), y_range=(0, 10))

# Solid line to show effect of alpha...
p.line([0, 10], [10, 0], color='red', line_width=2)
# Attempt to set global alpha of 0.5...
p.image_rgba(image=[img], x=0, y=0, dw=10, dh=10, alpha=0.5)

show(p)
```

The red line from top left to bottom right is not visible behind the image.

Software versions...
Bokeh 0.12.14
Python 3.6.4
Firefox 58.0.2 (64-bit)
Ubuntu MATE 16.04.4 LTS

NB: I'm working on a solution following conclusion of PR#7570.


Discussion:
Thanks @marcuskd !

Resolving patch:
diff --git a/bokeh/models/glyphs.py b/bokeh/models/glyphs.py
--- a/bokeh/models/glyphs.py
+++ b/bokeh/models/glyphs.py
@@ -402,7 +402,7 @@ class ImageRGBA(XYGlyph):
 
     # a canonical order for positional args that can be used for any
     # functions derived from this class
-    _args = ('image', 'x', 'y', 'dw', 'dh', 'dilate')
+    _args = ('image', 'x', 'y', 'dw', 'dh', 'global_alpha', 'dilate')
 
     image = NumberSpec(help="""
     The arrays of RGBA data for the images.
@@ -432,6 +432,11 @@ class ImageRGBA(XYGlyph):
         That number is fixed by the image itself.
     """)
 
+    global_alpha = Float(1.0, help="""
+    An overall opacity that each image is rendered with (in addition
+    to any inherent alpha values in the image itself).
+    """)
+
     dilate = Bool(False, help="""
     Whether to always round fractional pixel locations in such a way
     as to make the images bigger.
diff --git a/bokeh/plotting/helpers.py b/bokeh/plotting/helpers.py
--- a/bokeh/plotting/helpers.py
+++ b/bokeh/plotting/helpers.py
@@ -724,6 +724,10 @@ def func(self, **kwargs):
         renderer_kws = _pop_renderer_args(kwargs)
         source = renderer_kws['data_source']
 
+        # Assign global_alpha from alpha if glyph type is an image
+        if 'alpha' in kwargs and glyphclass.__name__ in ('Image', 'ImageRGBA', 'ImageURL'):
+            kwargs['global_alpha'] = kwargs['alpha']
+
         # handle the main glyph, need to process literals
         glyph_ca = _pop_colors_and_alpha(glyphclass, kwargs)
         _process_sequence_literals(glyphclass, kwargs, source, is_user_source)
diff --git a/examples/plotting/file/image_alpha.py b/examples/plotting/file/image_alpha.py
--- a/examples/plotting/file/image_alpha.py
+++ b/examples/plotting/file/image_alpha.py
@@ -1,6 +1,9 @@
 import numpy as np
 
 from bokeh.plotting import figure, show, output_file
+from bokeh.layouts import Column
+
+# 1. Adding alpha for the image method
 
 N = 500
 x = np.linspace(0, 10, N)
@@ -9,16 +12,48 @@
 d = np.sin(xx)*np.cos(yy)
 d[:125, :125] = np.nan  # Set bottom left quadrant to NaNs
 
-p = figure(x_range=(0, 10), y_range=(0, 10))
+p1 = figure(x_range=(0, 10), y_range=(0, 10))
 
 # Solid line to show effect of alpha
-p.line([0, 10], [0, 10], color='red', line_width=2)
-# Use global_alpha kwarg to set alpha value
-img = p.image(image=[d], x=0, y=0, dw=10, dh=10, global_alpha=0.7)
-# Alpha for color mapper attributes can be set explicitly and is applied prior to global alpha,
-# e.g. NaN color:
+p1.line([0, 10], [0, 10], color='red', line_width=2)
+# Use alpha kwarg to set alpha value
+img = p1.image(image=[d], x=0, y=0, dw=10, dh=10, palette="Spectral11", alpha=0.7)
+# Alpha for color mapper attributes can be set explicitly and is applied prior
+# to the global alpha, e.g. NaN color:
 img.glyph.color_mapper.nan_color = (128, 128, 128, 0.1)
 
-output_file("image_alpha.html", title="image_alpha.py example")
+# 2. Adding alpha for the image_rgba method
+
+N = 20
+img = np.empty((N, N), dtype=np.uint32)
+view = img.view(dtype=np.uint8).reshape((N, N, 4))
+c = 0
+for i in range(N):
+    for j in range(N):
+        view[i, j, 0] = int(i/N*255)
+        view[i, j, 1] = 158
+        view[i, j, 2] = int(j/N*255)
+        view[i, j, 3] = 127*(c % 3)  # Alpha rotates 0, 0.5, 1, 0, 0.5...
+        c += 1
+
+p2 = figure(x_range=(0, 10), y_range=(0, 10))
+
+# Solid line to show effect of alpha
+p2.line([0, 10], [10, 0], color='red', line_width=2)
+# Use alpha kwarg to set alpha value to 0.5: alpha now 0, 0.25, 0.5, 0, 0.25...
+p2.image_rgba(image=[img], x=0, y=0, dw=10, dh=10, alpha=0.5)
 
-show(p)  # open a browser
+# 3. Adding alpha for the image_url method
+
+url = 'http://bokeh.pydata.org/en/latest/_static/images/logo.png'
+
+p3 = figure(x_range=(0, 10), y_range=(0, 10))
+# Solid line to show effect of alpha
+p3.line([5, 5], [0, 10], color='red', line_width=2)
+# Use alpha kwarg to set alpha value
+p3.image_url(url=[url], x=0, y=0, w=10, h=10, anchor='bottom_left', alpha=0.3)
+
+# Display images
+
+output_file("image_alpha.html", title="image_alpha.py example")
+show(Column(p1, p2, p3))


Test patch:
diff --git a/bokeh/models/tests/test_glyphs.py b/bokeh/models/tests/test_glyphs.py
--- a/bokeh/models/tests/test_glyphs.py
+++ b/bokeh/models/tests/test_glyphs.py
@@ -194,6 +194,7 @@ def test_ImageRGBA():
         "dw_units",
         "dh",
         "dh_units",
+        "global_alpha",
         "dilate",
     ], GLYPH)