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

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

Closed
StevenCHowell opened this Issue Oct 20, 2016 · 7 comments

Comments

Projects
None yet
2 participants
@StevenCHowell
Member

StevenCHowell commented Oct 20, 2016

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)

@clairetang6 clairetang6 referenced this issue Nov 20, 2016

Merged

Fix for log scale plotting bug #5477

2 of 2 tasks complete

@bryevdv bryevdv added this to the 0.12.4 milestone Dec 10, 2016

@bryevdv bryevdv closed this Dec 12, 2016

@StevenCHowell

This comment has been minimized.

Member

StevenCHowell commented Dec 13, 2016

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)

image

@StevenCHowell StevenCHowell reopened this Dec 13, 2016

@StevenCHowell

This comment has been minimized.

Member

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

This comment has been minimized.

Member

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

This comment has been minimized.

Member

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

This comment has been minimized.

Member

bryevdv commented Dec 13, 2016

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

This comment has been minimized.

Member

bryevdv commented Dec 13, 2016

Screenshot for np.linspace(0.1, 0.9, 21):
screen shot 2016-12-13 at 11 04 37 am

screenshot for np.linspace(-0.1, 0.9, 21):

screen shot 2016-12-13 at 11 05 31 am

JS console reports "could not set initial ranges

@StevenCHowell

This comment has been minimized.

Member

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment