plot is empty when log scale is used #3834
Bokeh incorrectly creates an empty plot with the following:
from bokeh.plotting import figure, output_file, show ys = [4.471799184102565e-05, 0.0009856299875536934, 0.0011045119899790734] xs = range(len(ys)) output_file("log.html") p = figure(y_axis_type="log") p.line(xs, ys) show(p)
The problem only occurs if
It seems when the range of y values is too narrow bokeh fails to compute the y-axis range. If I multiple the y values by 100, it plots properly.
Tested on bokeh version: 0.11.1 py34_0
The text was updated successfully, but these errors were encountered:
@sklam This seems to be due to a problem bokeh has in computing the min and max value for a range that is used with log axes. As a workaround, you could just specify a range yourself, and it should work.
p = figure(y_axis_type="log", y_range=[10e-6, 10e-3])
When you don't put in a range yourself, then the default is to take the min and max of the data and add some padding to it, which is a percentage of the total range from data min to data max. The problem is that the padding is calculated linearly, which can cause problems in log plots, specifically when the padding is larger than the smallest data value. That causes the min value for the range to become negative, which is a problem for log axes since the log of a negative number is undefined.
This issue about range_padding is also related.
You could also compute a min and max value for the range using the range padding parameter in log space, something like:
log_ys = np.log(ys) log_range_padding = 0.2 * (log_ys[-1] - log_ys) log_range = [log_ys - log_range_padding, log_ys + log_range_padding] y_range = np.exp(log_range).tolist() #y_range is [2.354749231925326e-05, 0.0018717659249710699]
And then you could go on and find the next n-th powers so that you end up with nice and even major ticks like