Log scale using Bokeh's scatter function

坚强是说给别人听的谎言 提交于 2019-12-10 12:39:00

问题


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')

回答1:


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! ;-)



来源:https://stackoverflow.com/questions/25025021/log-scale-using-bokehs-scatter-function

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!