Set color for rasterized Segment

How can I choose the line color of a Segment after being rasterized ?

import holoviews as hv
from holoviews.operation.datashader import rasterize

# OK: line is grey
p = hv.Segments([(0, 0, 1, 1)])
p = p.opts(color="#EEEEEE")

# NOT OK: line is red
p = hv.Segments([(0, 0, 1, 1)])
p = p.opts(color="#EEEEEE")
p = rasterize(p)

# NOT OK: raised "ValueError("Unexpected option 'line_color' for Image type across all extensions.
p = hv.Segments([(0, 0, 1, 1)])
p = rasterize(p)
p = p.opts(color="#EEEEEE")

Note: additionally I’d like line_alpha and line_width to persist through rasterization/shade

The rasterize operation turns a HoloViews Element into an hv.Image object. An hv.Image needs a colormap, not a single color, mapping from the arbitrary numeric value in each grid cell into an appropriate color from a list. You can force all numeric values to map to the same single color if you supply a colormap that’s a list containing your one desired color: p = rasterize(p).opts(cmap=["#EEEEEE"]).

hv.Image objects take alpha rather than line_alpha (p = rasterize(p).opts(cmap=["#EEEEEE"], alpha=0.5)).

Unfortunately, there is no direct equivalent to line_width; Datashader currently only supports single-pixel lines. You can approximate it by calling spread, which uses image dilation to enlarge the line. As of the current HoloViews release, spread only works with datashade, not rasterize, but the upcoming hv 1.14 release will generalize spread to work with rasterize (at which point p = spread(rasterize(p), px=2).opts(cmap=["#EEEEEE"], alpha=0.5) will work).