Scatter plot with color of points depending on the magnitude of the values in the array

Hello everyone!
I need to plot points (x, y) from some dataset using different color of points depending on the magnitude of the value in another dataset Z. The dimensions of x, y, z are the same.

In short, how to write the same code using pylab but in Bokeh?

import numpy as np
import pylab as plt
plt.scatter(x, y, c=col, s=100)


I tried to find examples of the solution and came across to factor_cmap and linear_cmap
However could not find a solution that worked for me.

This is necessary in order to find outgoing points on similar datasets (like the one in the screenshot marked with an arrow).


See the accepted answer for the following StackOverflow topic, which uses a LinearColorMapper based on the petal length (numeric value) for a common iris data set used in classification problems.

The example is similar to your problem in key respects of (i) plotting circle glyphs and (ii) having the color tied to some numeric attribute.


Thank you so much.
I probably did not see this solution.
Below is the corrected code.

from bokeh.plotting import figure, show, output_file
from bokeh.sampledata.iris import flowers  
from bokeh.models import LinearColorMapper
from bokeh.models import ColumnDataSource

p = figure(title = "Exmpl")
p.xaxis.axis_label = "x"
p.yaxis.axis_label = "y"

source = ColumnDataSource({'x':x,'y':y,'col':col})

exp_cmap = LinearColorMapper(palette="Viridis256", 
                             low = min(col), 
                             high = max(col))"x", "y",size=25, source=source, line_color=None,
        fill_color={"field":"col", "transform":exp_cmap})

from bokeh.models import ColorBar
bar = ColorBar(color_mapper=exp_cmap, location=(0,0))
p.add_layout(bar, "left")