简体   繁体   中英

Quad with log axis in bokeh

Is it possible to use figure.quad() when the figure has y_axis_type='log' ? I'm able to plot the quad of the log transforms. I'm also able to plot a line with same values in a log axis. But when I try to plot a quad in a log axis, I get a blank figure. I'm using bokeh 0.12.9 . Below is some test code with the expected output ...

from bokeh.io import export_png
from bokeh.layouts import gridplot
from bokeh.plotting import figure
import numpy as np

N = 50
left = np.arange(N)
right = np.arange(1, N+1)
bottom = np.zeros(N)
top = 100 * np.sin(np.pi*left/N)**2 + 1 

fig_args = dict(width=400, height=400, tools="")

f1 = figure(**fig_args, title='Quad')
f1.quad(left=left, right=right, top=top, bottom=bottom, line_color='black')

f2 = figure(**fig_args, title='Quad of Logs')
f2.quad(left=left, right=right, top=np.log10(top), bottom=bottom, line_color='black')

f3 = figure(**fig_args, y_axis_type='log', title='Line w/Log Axis')
f3.line(left, top)

f4 = figure(**fig_args, y_axis_type='log', title='Quad w/Log Axis')
f4.quad(left=left, right=right, top=top, bottom=bottom, line_color='black')

lout = gridplot([f1, f2, f3, f4], ncols=2)
export_png(lout, 'test.png')

在此处输入图片说明

There are still open issues to determine how best to have Bokeh handle zero points in log scales. From a purely mathematical viewoint, they don't make much sense. There are a few possible practical approaches to take, but none of them have been implemented yet. However, if you provide explicit direction, you can get the plot you need. You can see this by using something other than 0 as the bottom value, and explicitly setting the y_range :

f4 = figure(**fig_args, y_axis_type='log', title='Quad w/Log Axis', y_range=(1, 200))
f4.quad(left=left, right=right, top=top, bottom=0.000000001, line_color='black')

Yields this image:

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM