Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log scale using Bokeh's scatter function

Tags:

python

bokeh

How do I get log scales when using Bokeh's scatter function. I'm looking for something like the following:

scatter(x, y, source=my_source, ylog=True)

or

scatter(x, y, source=my_source, yscale='log')
like image 373
MRocklin Avatar asked Jul 29 '14 21:07

MRocklin


1 Answers

Something along these lines will work:

import numpy as np
from bokeh.plotting import *

N = 100

x = np.linspace(0.1, 5, N)

output_file("logscatter.html", title="log axis scatter example")

figure(tools="pan,wheel_zoom,box_zoom,reset,previewsave",
       y_axis_type="log", y_range=[0.1, 10**2], title="log axis scatter example")

scatter(x, np.sqrt(x), line_width=2, line_color="yellow", legend="y=sqrt(x)")

show()

Alternative you can also pass the "log"-related parameters in the scatter call instead of figure (but I recommend you to write it as I showed above):

scatter(x, np.sqrt(x), y_axis_type="log", y_range=[0.1, 10**2], line_width=2, line_color="yellow", legend="y=sqrt(x)")

Hope it helps! ;-)

like image 61
Damian Avila Avatar answered Sep 23 '22 10:09

Damian Avila