使用Bokeh的散点函数绘制对数刻度
我想知道如何在使用Bokeh的scatter
函数时实现对数坐标轴的效果。我希望能得到类似下面这样的效果:
scatter(x, y, source=my_source, ylog=True)
或者
scatter(x, y, source=my_source, yscale='log')
1 个回答
21
类似这样的代码可以正常工作:
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()
另外,你也可以在散点图的调用中传入与“日志”相关的参数,而不是在图形中传入(不过我建议你还是按照我上面展示的方式写):
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)")
希望这对你有帮助!;-)