question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Force log axes to remain positive

See original GitHub issue

I have noticed when linking the axes of a log plot to a linear plot of the same data, the resulting figure fails gloriously when dragging the linear axis negative. This is related to issue #5389, #5549, and PR #5477.

I see two ways to prevent problems when users inadvertently designate a situation that does not really make sense for a log plot,

  1. impose an axis-limit-override for log scale so the lower limit is ALWAYS greater than zero, i.e., ignore commands to set the limit to zero or negative
  2. somehow determine minimum value to show, below the the lowest data value, then mirror the axis to negative, then show that space empty (log(n) > 0 so it would never have data), i.e., the smallest data value is 1e-9 so draw the axis at 1e-10 and mirror across the axis

I am not sure which would be preferred/easier, and there are likely other options worth considering, ideas?

Here is an simple example to demonstrate the strange behavior (note that this was run before PR #5477):

import numpy as np
from bokeh.models import Range1d
from bokeh.layouts import gridplot
from bokeh.plotting import figure, show, output_notebook
output_notebook()

x = np.linspace(0.001, 0.9, 300)
y = (np.sin(15 * x) / (15 * x)) ** 2 # fake small-angle scattering data

p1 = figure(title='Linear Scale', x_axis_label='q (1/A)', y_axis_label='I(q)',
            width=400, height=400)
p2 = figure(title='Log Scale', x_axis_label='q (1/A)', y_axis_label='I(q)', 
            width=400, height=400, x_axis_type='log', y_axis_type='log')

p1.circle(x, y)
p2.circle(x, y)

# pre PR #5477 bit to force the log range to be correct
x_range = np.min(x[x > 0]) * 0.9, np.max(x) * 1.1
y_range = np.min(y[y > 0]) * 0.9, np.max(y) * 1.1
p2.x_range = Range1d(*x_range)
p2.y_range = Range1d(*y_range)

# set the ranges to match
p1.x_range = p2.x_range
p1.y_range = p2.y_range

fig = gridplot([[p1, p2]])
show(fig)

When dragging the plots, the axis can reverse negative-to-positive, the zoom changes to where you can lose track of where the data is, and possibly other strange behaviors. Here is the original plot image

and here is an example of the y-axes inverting image

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
StevenCHowellcommented, Jan 31, 2017

Thank you @clairetang6 for addressing this issue!

0reactions
StevenCHowellcommented, Jan 31, 2017

I just tested panning the plots generated by the code in my original comment. In the current dev build, 0.12.5dev11, panning works great. When the dragging the linear plot beyond the limits of the log plot, the log plot pauses until and the linear plot returns to possible limits of the log plot.

I also tested the current release build, 0.12.4 (0.12.4-py35_0), and the problems persist there.

As long as nothing gets reverted, I think this safe to close as the 0.12.5 update should resolve the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Bokeh how to show negative log scale in x and y axis?
If there are no zero values, plot using the absolute values of the coordinates to keep everything in the positive quadrant. Then you...
Read more >
how to set y-axis as log scale? - MATLAB Answers
If you want negative values to be displayed where the corresponding positive value would be displayed, then plot with abs(y) instead of y....
Read more >
How can I set the axis scaling of plots to linear or logarithmic?
will use a logarithmic scale for both the fit and residual plots, which is not ideal (since the residual plot should include negative...
Read more >
Dealing with Zeros and Negative Values with a Log Scale
A log-scaled axis does have its limitations, though. Namely, values cannot be zero or negative, since the logarithm of those values are not ......
Read more >
You should (usually) log transform your positive data
In such a situation, it might seem to make sense to stay on the original scale for reasons of simplicity. However, the logarithmic ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found