☰Read-only archive⌕
Looking for help with Bokeh?

This is a read-only archive. Ask questions and join the conversation on GitHub.

Visit Community Support on GitHub →
Archived discussions · Captured October 28, 2026

Bokeh unable to handle RGB/RGBA tuples

Community Support
excess.gravy
excess.gravy

Hey,

I’ve been trying to use bokeh to plot arrays of data with unique colors, but have yet to be successful. Has any one been able to get a working bokeh plot with RGB/RGBA tuples?

Here’s a sample script I was using to plot data. In the matplotlib example I get all the desired colors, but in the bokeh plots they all come out as grey.

import matplotlib.pyplot as plt
import numpy as np

# Import bokeh
import bokeh
import bokeh.plotting

NUM_COLORS = 20

cm = plt.get_cmap('gist_rainbow')

# Define the output file
bokeh.plotting.output_file(filename='quantities.html')

# Define the figure
figure = bokeh.plotting.figure(plot_width=1000, plot_height=600)

# Go through the number of colors
for ix in range(NUM_COLORS):

    # color will now be an RGBA tuple
    color = cm(1.*ix/NUM_COLORS)

    # Define generic data
    x = np.arange(0, 10)
    y = np.arange(0, 10) + ix

    # Plot the data bokeh style
    figure.line(x, y, line_color=color, line_width=2, legend=str(ix))
    figure.scatter(x, y, color=color)

    # Plot the data mpl style
    plt.plot(x, y, color=color)

# Show the bokeh plot
bokeh.plotting.show(figure)

# Show the matplotlib plot
plt.show()

⌁   Link to post
excess.gravy
excess.gravy

That didn’t seem to work for me either. Any other ideas?

···

On Friday, April 3, 2015 at 3:25:46 PM UTC-7, pwang wrote:

In the “color = cm(1. * ix/NUM_COLORS)” line, try multiplying by 255.​

-Peter

⌁   Link to post
Fabio_Pliger
Fabio_Pliger

Apparently it’s a bug. I’ve created a related issue on GH that contains the bug details.

In the meanwhile (as posted on that issue) you use bokeh.colors.RGB to explicitly convert the color when passing it to bokeh. Of course, as Peter suggested, you need to multiply you color tuple values by 255 first. Here’s a working version of you example:

import matplotlib.pyplot as plt

import numpy as np

Import bokeh

import bokeh

import bokeh.plotting

from bokeh.colors import RGB

NUM_COLORS = 20

cm = plt.get_cmap(‘gist_rainbow’)

Define the output file

bokeh.plotting.output_file(filename=‘quantities.html’)

Define the figure

figure = bokeh.plotting.figure(plot_width=1000, plot_height=600)

Go through the number of colors

for ix in range(NUM_COLORS):

color will now be an RGBA tuple

color = np.asarray(cm(1.*ix/NUM_COLORS)) * 255

color = RGB(*color).to_hex()

Define generic data

x = np.arange(0, 10)

y = np.arange(0, 10) + ix

Plot the data bokeh style

figure.line(x, y, line_color=color, line_width=2, legend=str(ix))

figure.scatter(x, y, color=color)

Plot the data mpl style

plt.plot(x, y, color=color)

# Show the bokeh plot

bokeh.plotting.show(figure)

``

Best

Fabio

···

On Tuesday, April 7, 2015 at 8:24:16 PM UTC+2, excess...@gmail.com wrote:

That didn’t seem to work for me either. Any other ideas?

On Friday, April 3, 2015 at 3:25:46 PM UTC-7, pwang wrote:

In the “color = cm(1. * ix/NUM_COLORS)” line, try multiplying by 255.​

-Peter

⌁   Link to post

End of archived discussion · Replies are disabled