Skip to content
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

Default LinearSpace values causes confusion #1493

Open
nicole-brewer opened this issue May 4, 2022 · 0 comments
Open

Default LinearSpace values causes confusion #1493

nicole-brewer opened this issue May 4, 2022 · 0 comments

Comments

@nicole-brewer
Copy link

This issue is not technically a bug, but this issue caused me a lot of unnecessary confusion as a new user and may be worth changing, addressing, or just documenting for other users who are searching for answers.

The issue is that a the default minimum and maximum values for a LinearScale of a horizontal line are both zero. This means that the Y-axis has no relative scale, which is indicated by the presence of a single tick indicating y-value of the horizontal line, as shown below:

Screen Shot 2022-05-04 at 5 32 26 PM

This technically makes sense, but this default behavior was very confusing to me as a new user. The code below is what produced the line/scatterplot shown above. I was attempting to move a point on the scatterplot and observe how far that point had traversed the y-axis.

from bqplot import *
from IPython.display import display

y = np.array([0, 0, 0])
x = np.array([-1, 0, 1])

x_sc = LinearScale()
y_sc = LinearScale(min=-1, max=1)

ax_x = Axis(label='Test X', scale=x_sc, tick_format='0.0f')
ax_y = Axis(label='Test Y', scale=y_sc,
            orientation='vertical', tick_format='0.2f')

line = Lines(x=x,
             y=y,
             scales={'x': x_sc, 'y': y_sc})

scatter = Scatter(x=x,
             y=y,
             scales={'x': x_sc, 'y': y_sc},
             enable_move=True,
             restrict_y=True)

def on_start(s, change):
    print(change)
    
def on_change(s, change):
    print(change)
    
def on_end(s, change):
    print(change)
    
scatter.on_drag_end(on_end)
scatter.on_drag(on_change)
scatter.on_drag_start(on_start)

fig = Figure(axes=[ax_x, ax_y],
             marks=[line , scatter])
display(fig)

But because the y-axis LinearScale had min=0 and max=0, this relative movement has no meaning. Not understanding this, I was very confused by the results I got on moving a scatter point.

Screen Shot 2022-05-04 at 5 32 41 PM

When I finally figured out what was wrong, I realized the fix was to set a non-zero minimum and maximum to the y-axis LinearScale. With a small change to line 8 of the code above...

y_sc = LinearScale(min=-1, max=1)

I was able to obtain more sensical results on dragging the scatter plot, as shown below.

Screen Shot 2022-05-04 at 5 33 42 PM

This is not a bug, but perhaps an intentional design decision to remain agnostic to infinite possible choices of scale on the y-axis. There may be other reasons also. However given my experience, I think it would be better to avoid confusion and set the default values of LinearScale to min=-1, max=1 when there is a vertical or horizontal line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant