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.

hline(0) not in correction position when plotting with object model

See original GitHub issue

vline(0) appears in the right place, but hline(0) does not. hline(0) seems to always be positioned at the minimum y value on the axis, rather than at y=0.

from bqplot import *
from bqplot.pyplot import vline, hline
import numpy as np

np.random.seed(3)
x_data = np.random.randn(1, 10)[0] + 1
y_data = np.random.randn(1, 10)[0] + 1

sc_x = LinearScale()
sc_y = LinearScale()
scales_dict = {'x': sc_x, 'y': sc_y}

scatt = Scatter(x=x_data, y=y_data, scales=scales_dict)

ax_x = Axis(scale=sc_x, label='x')
ax_y = Axis(scale=sc_y, orientation='vertical', label='y')

vline_mark = vline(0, scales = scales_dict)
hline_mark = hline(0, scales = scales_dict)
fig = Figure(marks=[scatt, vline_mark, hline_mark], axes=[ax_x, ax_y], animation_duration=1000)

display(fig)

image

When updating mark positions, vline behaves as expected but hline moves to new (but still incorrect position).

fig.marks[0].x = fig.marks[0].x - 2
fig.marks[0].y = fig.marks[0].y - 2

image

bqplot 0.11.0 IPython 7.0.1

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
martinRenoucommented, Jan 14, 2020

I suppose, yes. Maybe you would need to create a Line mark that has its own x and y scales?

1reaction
DougRzzcommented, Oct 22, 2018

I tried to find a work around. The hline_mark.y value seems to be a fraction of the height in y. You would have to add the min + max to the scale. Its not quite right but its quite close…

from bqplot import *
from bqplot.pyplot import vline, hline
import numpy as np

np.random.seed(3)
x_data = np.random.randn(1, 10)[0] + 1
y_data = np.random.randn(1, 10)[0] + 1

sc_x = LinearScale()
sc_y = LinearScale()
scales_dict = dict(x = sc_x, y= sc_y)

scatt = Scatter(x=x_data, y=y_data, scales=scales_dict)

ax_x = Axis(scale=sc_x, label='x')
ax_y = Axis(scale=sc_y, orientation='vertical', label='y')

vline_mark = vline(0, scales = scales_dict)
hline_mark = hline(0, scales = scales_dict)
# hline_mark.scales = scales_dict
fig = Figure(marks=[scatt, vline_mark, hline_mark], axes=[ax_x, ax_y], animation_duration=1000)
fig.padding_y =0
sc_y.max = 5
sc_y.min = -3

minMaxFraction = (-sc_y.min ) /(sc_y.max  - sc_y.min )
hline_mark.y=[minMaxFraction,minMaxFraction]
display(fig)

image

Read more comments on GitHub >

github_iconTop Results From Across the Web

hline(0) not in correction position when plotting with ... - GitHub
vline (0) appears in the right place, but hline(0) does not. hline(0) seems to always be positioned at the minimum y value on...
Read more >
Trouble with hline indices not changing when running ...
I moved my yintercept values into the aes of the lines and it worked perfectly. Correct hlines and all my legends.
Read more >
Syntax: PROC SGPLOT HLINE Statement - SAS Help Center
When DISCRETEOFFSET= and DATALABELPOS= are both specified, the DISCRETEOFFSET= option has no effect on the data labels. Only the plot is offset. ·...
Read more >
Plot a Horizontal line in Matplotlib - GeeksforGeeks
Plotting a horizontal line is fairly simple, Using axhline() ... y: Position on Y axis to plot the line, It accepts integers.
Read more >
A ggplot2 Tutorial for Beautiful Plotting in R - Cédric Scherer
But this data could be also visualized as a line plot (not optimal, ... adjust the position of the text afterwards horizontally (0...
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