Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

plot is empty when log scale is used #3834

Closed
sklam opened this issue Feb 5, 2016 · 4 comments
Closed

plot is empty when log scale is used #3834

sklam opened this issue Feb 5, 2016 · 4 comments

Comments

@sklam
Copy link

@sklam sklam commented Feb 5, 2016

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 y_axis_type="log" is used.

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

@clairetang6
Copy link
Contributor

@clairetang6 clairetang6 commented Mar 1, 2016

@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[0])
log_range = [log_ys[0] - log_range_padding, log_ys[1] + 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 y_range=[10e-6, 10e-3].

@bryevdv bryevdv added type: bug and removed type: discussion labels Apr 8, 2016
@bryevdv bryevdv added this to the short-term milestone Apr 8, 2016
@bryevdv
Copy link
Member

@bryevdv bryevdv commented Apr 8, 2016

This is still present on 0.12dev

@leopd
Copy link

@leopd leopd commented Nov 14, 2016

This is still present in 0.12.3.

Can somebody please look at this? You have multiple very simple repro cases. It results in random failures in a really fundamental feature: log-scale plotting.

@leopd
Copy link

@leopd leopd commented Nov 14, 2016

Here's a suggestion for a simple fix for you: set range-padding to 0 when axis is log-scale.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants