pythonlegendbokehcolor-mapping

python bokeh colour palette legend


I am trying out the awesome Bokeh visualization library for Python. I have one question on it. I am making something like a contour plot using this example as a reference.

It's working great but to complete this I would love to have the color map as a legend. Basically I want the reader of the graph to be able to understand what the colors mean. Is there a ways to do this?


Solution

  • There's now a ColorBar class for doing this. See

    http://docs.bokeh.org/en/latest/docs/user_guide/annotations.html#color-bars

    from bokeh.models import ColorBar, LogTicker
    
    color_bar = ColorBar(color_mapper=color_mapper, ticker=LogTicker(),
                     label_standoff=12, border_line_color=None, location=(0,0))
    plot.add_layout(color_bar, 'right')