如何在使用 Bokeh 的 scatter
函数时获取对数刻度。我想要类似以下的效果:
scatter(x, y, source=my_source, ylog=True)
或者scatter(x, y, source=my_source, yscale='log')
以下的内容应该可以解决问题:
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()
你也可以在散点图调用中传递与"log"相关的参数,而不是在图表中传递(但我建议你按照我上面展示的方式编写):
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)")
希望能帮到你!;-)