bqplot is an interactive framework for the Jupyter Notebook. Together with vaex it enables interactive plots, meaning you can zoom in and out, and do selections from the plot. The plot will also update for instance when you change the selection programmatically (Using Dataset.select ), or when done from the gui.
See bqplot installation instructions, or for pip:
$ pip install bqplot
$ jupyter nbextension enable --py bqplot
And anaconda/conda
$ conda install -c conda-forge bqplot
In [7]:
import bqplot.pyplot as plt
In [6]:
import bqplot
bqplot._version.version_info
Out[6]:
In [3]:
bqplot.__file__
Out[3]:
In [9]:
x = np.linspace(0, 1, 10)
y = x**2
plt.scatter(x, y)
plt.show()
In [1]:
# only used in develop mode (remove this)
%load_ext autoreload
%autoreload 2
In [5]:
import vaex as vx
import ipywidgets as widgets
import numpy as np
In [4]:
# use the taxi dataset
ds = vx.datasets.nyctaxi_yellow_2015_jan.fetch()
# or do whole 2015
# ds = vx.datasets.nyctaxi_2015.get()
# we'll show pickup and dropoff locations
pickups = ds("pickup_longitude", "pickup_latitude")
dropoffs = ds("dropoff_longitude", "dropoff_latitude")
# default region we'll look at
geo_limits = lonrange, latrange = (-74.0655186833, -73.8048761181), (40.6444424556, 40.9050850209)
print("{:,} rows".format(len(ds)))
In [5]:
(w1.__class__.__base__)
In [6]:
pickups.plot_bq(size=512, limits=geo_limits, f=np.log1p)
In [7]:
size = 512
# plot bq returns a ipywigets VBox object, the first child object is the figure, and we use that to connect
# the scales of the two figures
w1 = pickups.plot_bq(size=size, limits=geo_limits, tool_select=True, title="Pickups", f=np.log1p)
fig = w1.children[0]
scales = fig.marks[-1].scales
w2 = dropoffs.plot_bq(size=size, limits=geo_limits, tool_select=True, scales=scales, title="Dropoffs", f=np.log1p)
widgets.HBox([w1, w2])
In [56]:
# selecting work dropoff hours
ds.select("(pickup_hour >= 7) & (pickup_hour <= 9)")
In [75]:
# here is where the nightlive is
ds.select("(pickup_hour >= 23) | (pickup_hour <= 4)")
In [58]:
b = widgets.Button(description="Blaat")
In [59]:
b
In [60]:
b
In [61]:
def f(arg):
print arg
b.on_click(f)
In [62]:
b.description = "Hoeba"
In [65]:
@widgets.interact(bla=["aap", "noot"])
def f(i=1., j=1, bla="aap"):
print i, j, bla
In [66]:
t = widgets.Text()
In [67]:
t
In [68]:
t.value = "Hallo"
In [69]:
t2 = widgets.Text()
In [70]:
t2
In [73]:
widgets.ColorPicker()
In [ ]: