You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I came across a subtle bug in the way plotting.bokeh.colormap_generator normalizes colormaps with the default arguments, such that something like hv.Palette(f'Category{N}', samlples=N) will not return every color in the colormap. Example here for N=10:
Two pinks (#e377c2) are returned and gray (#7f7f7f) is missing.
This can be fixed by adding a very small term to the upper value of the range argument (e.g., (0, 1+1e-10)), but is mainly related to floating point error in what plotting.bokeh.colormap_generator returns:
Clearly that value is supposed to be 7 but int(6.9999...) is 6.
I played around with other types of creating that integer (e.g., round), but the best method I found that always keeps the same expected behavior for all colormaps and also fixes these float errors is to just add a small term in the colormap_generator function:
def colormap_generator(palette):
# Account for potential floating point error
error = 1e-10
return lambda value: palette[int(value*(len(palette)-1)+error)]
This fixes the issue and returns the expected behavior:
I've got a fork with this fixed and can open a PR, but it's honestly a 1/2-line fix, so I figured an actual dev could just make that change easily enough.
The text was updated successfully, but these errors were encountered:
I came across a subtle bug in the way
plotting.bokeh.colormap_generator
normalizes colormaps with the default arguments, such that something likehv.Palette(f'Category{N}', samlples=N)
will not return every color in the colormap. Example here forN=10
:Two pinks (#e377c2) are returned and gray (#7f7f7f) is missing.
This can be fixed by adding a very small term to the upper value of the
range
argument (e.g.,(0, 1+1e-10)
), but is mainly related to floating point error in whatplotting.bokeh.colormap_generator
returns:Clearly that value is supposed to be
7
butint(6.9999...)
is6
.I played around with other types of creating that integer (e.g.,
round
), but the best method I found that always keeps the same expected behavior for all colormaps and also fixes these float errors is to just add a small term in thecolormap_generator
function:This fixes the issue and returns the expected behavior:
I've got a fork with this fixed and can open a PR, but it's honestly a 1/2-line fix, so I figured an actual dev could just make that change easily enough.
The text was updated successfully, but these errors were encountered: