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

Bars object does not respect min or max of x-LinearScale correctly #880

Open
andymcarter opened this issue Jul 3, 2019 · 2 comments
Open

Comments

@andymcarter
Copy link

Describe the bug
When using the Bars object together with a LinearScale, the min and max attributes of the scale does affect the chart plotting areas, but the precise min and max values are not respected.

The behaviour appears to be correct for a y-axis LinearScale.

To Reproduce
import bqplot as bqp
x_sc = bqp.LinearScale(min=0)
y_sc = bqp.LinearScale()
ax_x = bqp.Axis(scale = x_sc)
ax_y = bqp.Axis(scale = y_sc, orientation='vertical')

bars = bqp.Bars(x = [10,12,14], y = [10,12,14], scales={'x': x_sc, 'y': y_sc})

fig = bqp.Figure(marks = [bars], axes = [ax_x, ax_y,])
fig

Expected behavior
The chart x axis should start from 0.

Screenshots
image

Environment (please complete the following information):

  • macOS, Chrome, bqplot 0.11.5

Additional context
Add any other context about the problem here.

@marketneutral
Copy link

I am also observing that LinearScale does not respect min or max in the pyplot API. Example:

import pandas as pd
import numpy as np
from datetime import datetime
from bqplot import pyplot as blt
from bqplot import LinearScale
from ipywidgets import HBox

def event_handler(name, value):
    sel = price_line.selected
    if sel is None or len(sel) < 2:
        pass
    else:
        zoomed_ts = ts.iloc[sel[0]:sel[-1]:, ]
        zoom_line.y = zoomed_ts.values
        zoom_line.x = zoomed_ts.index.values

start_date = datetime(2000,1,1)
end_date = datetime.today()
dates = pd.date_range(start_date, end_date, freq='M')
ts = pd.DataFrame(data=np.random.rand(len(dates),1), index=dates, columns=['XYZ']).cumsum()

price_fig = blt.figure()
price_line = blt.plot(ts.index.values, ts.values)
blt.axes()['x'].tick_format = '%b-%Y'
blt.axes()['x'].num_ticks = 5
brush = blt.int_selector(event_handler)

zoom_fig = blt.figure()
zoom_line = blt.plot(ts.index.values, ts.values)
zoom_line.scales['y'] = LinearScale(min=0, max=100)

image

The y-axis on the plot on the right should not exceed 100.

I also expected the axis to be fixed at 0 to 100, as it would be in matplotlib when you set the range of the axis.

@thirdreplicator
Copy link

As a work-around you can use:

plt.ylim(0, 100)

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

3 participants