/ bokeh Public

# Creating a line plot with `x_axis_type='log'` fails when `x_max < 1`#5389

Closed
opened this issue Oct 20, 2016 · 7 comments
Closed

# Creating a line plot with `x_axis_type='log'` fails when `x_max < 1` #5389

opened this issue Oct 20, 2016 · 7 comments
Labels
Milestone

### StevenCHowell commented Oct 20, 2016 • edited

 When creating a plot with a logarithmic scale on the x-axis, if the maximum x-value is less than 1 the x-axis decreases from left to right, the scale is linear, not logarithmic, and the default view does not show the data. I tested various values for the maximum x-value and found that when x_max > 1, the x-axis increases left to right but the default view only shows x > 1. This code demonstrates the problem ``````import numpy as np from bokeh.plotting import figure, output_file, show output_file('test.html') x = np.linspace(0, 0.95) # x decreases left to right, linear scale # x = np.linspace(0, 1) # x increases left to right but default view shows, 1 < x < 1.05 # x = np.linspace(0, 10) # x increases left to right but default view shows, 1 < x < 10.5 y = np.sin(x)/x p = figure(x_axis_type='log') p.line(x, y) show(p) `````` I tried declaring the x_range for the figure using `x_range=(x.min(), x.max())` but this had to effect unless I removed the zero point from the data, i.e., `x = x[x > 0]`. With theses changes, the x-axis increases left to right and the default view shows the range indicated. Here is a functional workaround ``````import numpy as np from bokeh.plotting import figure, output_file, show output_file('test.html') x = np.linspace(0, 0.95) # x decreases left to right, linear scale x = x[x > 0] y = np.sin(x)/x p = figure(x_axis_type='log', x_range=(x.min(), x.max())) p.line(x, y) show(p) `````` I did not test all these same conditions with `y_axis_type` but I expect it to have the same problems. I did notice that the default view only shows `y > 1`, even if the data begins ay `y < 1`. Here are the key points that need to be verified for logarithmic x and y axes: make sure the x-axis decreases left to right when the maximum x-value is less than 1 make sure the y-axis increases bottom to top when the maximum y-value is less than 1 adjust the default view to ignore x<=0 or y<=0 but show all other data (including x<1 and y<1) The text was updated successfully, but these errors were encountered:

### StevenCHowell commented Dec 13, 2016 • edited

 Did this PR get into the `0.12.4dev8` build? If so, the axis is still rendered incorrectly if the maximum x-value is ~1 or less. Here is a demo of what I am seeing: ``````import bokeh print(bokeh.__version__) import numpy as np from bokeh.plotting import figure, show, output_notebook from bokeh.layouts import gridplot from bokeh.palettes import Colorblind8 as palette output_notebook() values = np.linspace(-1, 1, 21) print(values) size = 250 semilogx = figure(title='semilogx test', x_axis_type='log', width=size, height=size) semilogy = figure(title='semilogy test', y_axis_type='log', width=size, height=size) loglog = figure(title='loglog test', x_axis_type='log', y_axis_type='log', width=size, height=size) semilogx.line(values[values != 0.0], values[values != 0.0]) semilogy.line(values, values) loglog.line(values, values) fig = gridplot([[semilogx, semilogy, loglog]]) show(fig) `````` ### StevenCHowell commented Dec 13, 2016

 Just realized this PR likely did not get into the `0.12.4dev8` build (updated my comment to reflect that). I will run it from source with this example to test, then close this if it does work. Sorry I did not do that first.

### bryevdv commented Dec 13, 2016

 This was not in `dev8` I don't think. I want to make `dev9` but am waiting to hear back from TravisCI support about an issue on their end causing one of our builds to continuously fail first.

### bryevdv commented Dec 13, 2016

 @StevenCHowell from my testings: the original example now works. However, there seems to be problems with data values < 0 as best I can tell.

### bryevdv commented Dec 13, 2016 • edited

 i.e. this works: ``````values = np.linspace(0.1, 0.9, 21) `````` But this is blank: ``````values = np.linspace(-0.1, 0.9, 21) `````` ping @clairetang6 Given that the OP code seems to work, I guess I'd be more in favor of a new issue at this point. But thoughts welcome

### bryevdv commented Dec 13, 2016 • edited

 Screenshot for `np.linspace(0.1, 0.9, 21)`: screenshot for `np.linspace(-0.1, 0.9, 21)`: JS console reports "could not set initial ranges

### StevenCHowell commented Dec 13, 2016

 This looks good. It can be a separate issue. Thanks @clairetang6 and @bryevdv, this was a big step in making bokeh easier to use for my data (sorry I never actually helped fix anything rather than only criticizing).

This was referenced Dec 13, 2016