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.

[BUG] Behaviour of automated padding for ranges is inconsistent

See original GitHub issue

Exists in Bokeh from 0.13.0 till 1.4.0 Tested on Windows 10 and Ubunto 16.0, on Firefox and Chrome (most recent versions).

That’s the weird bug, so explanation will be rather long.

Example 1:

from bokeh.plotting import figure, output_file, show

x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]
y1 = [30 for xx in x]

legend_items = []
p = figure(plot_width=500, plot_height=400)
l1 = p.line(x, y1, line_width=2, color='red')
p.y_range.start = 0
li1 = LegendItem(label='Line 1', renderers=[l1])
legend_items.append(li1)
legend = Legend(items=legend_items, location=(0, -30))
legend.click_policy = "hide"
p.add_layout(legend, 'left')

show(p)

That produces pretty looking chart: image

Automatic padding added a little bit of space between horizontal line and top end of the chart, so line is clearly visible.

Example 2:

from bokeh.plotting import figure, output_file, show

x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]
y1 = [300 for xx in x]

legend_items = []
p = figure(plot_width=500, plot_height=400)
l1 = p.line(x, y1, line_width=2, color='red')
p.y_range.start = 0
li1 = LegendItem(label='Line 1', renderers=[l1])
legend_items.append(li1)
legend = Legend(items=legend_items, location=(0, -30))
legend.click_policy = "hide"
p.add_layout(legend, 'left')

show(p)

image

With line located at Y=300, there’s no automatic padding added, so line located directly on the border of the chart.

One can argue, it can be easily fixed bu using customized y_range, but manually setting y_range bounds makes it hard to use new feature from 1.4.0 (https://github.com/bokeh/bokeh/issues/9144):

Example 3 (only works in Bokeh 1.4.0):

from bokeh.plotting import figure, output_file, show

x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]
y1 = [30 for xx in x]
y2 = [60 for xx in x]
y3 = [90 for xx in x]

legend_items = []

# create a new plot with a log axis type
p = figure(plot_width=500, plot_height=400)

l1 = p.line(x, y1, line_width=2, color='red')
l2 = p.line(x, y2, line_width=2, color='blue')
l3 = p.line(x, y3, line_width=2, color='green')

p.y_range.start = 0

li1 = LegendItem(label='Line 1', renderers=[l1])
li2 = LegendItem(label='Line 2', renderers=[l2])
li3 = LegendItem(label='Line 3', renderers=[l3])
legend_items.append(li1)
legend_items.append(li2)
legend_items.append(li3)

p.y_range.only_visible = True

legend = Legend(items=legend_items, location=(0, -30))
legend.click_policy = "hide"
p.add_layout(legend, 'left')

show(p)

Now we are using automated Y-range scaling. All lines are clearly visible no matter how many lines we have hidden:

image

or

image

But if we change Y-values for lines back to 300…

Example 4 (only works in Bokeh 1.4.0):

from bokeh.plotting import figure, output_file, show

x = [0.1, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0]
y1 = [300 for xx in x]
y2 = [600 for xx in x]
y3 = [900 for xx in x]

legend_items = []

# create a new plot with a log axis type
p = figure(plot_width=500, plot_height=400)

l1 = p.line(x, y1, line_width=2, color='red')
l2 = p.line(x, y2, line_width=2, color='blue')
l3 = p.line(x, y3, line_width=2, color='green')

p.y_range.start = 0

li1 = LegendItem(label='Line 1', renderers=[l1])
li2 = LegendItem(label='Line 2', renderers=[l2])
li3 = LegendItem(label='Line 3', renderers=[l3])
legend_items.append(li1)
legend_items.append(li2)
legend_items.append(li3)

p.y_range.only_visible = True

legend = Legend(items=legend_items, location=(0, -30))
legend.click_policy = "hide"
p.add_layout(legend, 'left')

show(p)

For 3 lines it works fine:

image

For 2 lines it works fine:

image

But with only 1 line visible automated padding not working again:

image

What I would expect?

I would expect to see similar gap between red line and top boundary of the chart, as I see for blue and green lines.

Why it’s important?

Without callbacks there’s no way to change y_range for the chart when certain lines became hidden and visible. As far as I understand, #9144 was supposed to provide simple way to do so, but since automated padding not always working the way you expect it to work, it’s almost useless.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
bryevdvcommented, Feb 28, 2020

@Tikonderoga yes exactly PRs from forks are the standard way to proceed

0reactions
Tikonderogacommented, Feb 28, 2020

And follow-up question: is there any instructions how to contribute to bokeh source code? Or is it just “create branch -> test -> create pull request” routine?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why is there extra padding at the top of my UITableView with ...
The tableview starts at the first arrow, there are 35 pixels of unexplained padding, then the green header is a UIView returned by...
Read more >
padding - CSS: Cascading Style Sheets - MDN Web Docs
An element's padding area is the space between its content and its border. Note: Padding creates extra space within an element. In contrast, ......
Read more >
CRADLE: Cross-Backend Validation to Detect and Localize ...
CRADLE detects 12 bugs and 104 unique inconsistencies, and ... Users of DL systems have a diverse range of background, ... based on...
Read more >
Common Mistakes - OpenGL Wiki - Khronos Group
The base/max level is a closed range), then perform a glTexImage2D (note the lack of "Sub") for each mipmap. Automatic mipmap generation.
Read more >
The CSS layout model: borders, boxes, margins and padding
However, when such a margin is applied to an element with a meaningful width, an auto margin instead causes all of the available...
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