conda install -c conda-forge ipyleaflet
In [ ]:
from ipyleaflet import Map, basemaps, basemap_to_tiles
In [ ]:
center = (52.204793, 360.121558)
m = Map(
layers=(basemap_to_tiles(basemaps.NASAGIBS.ModisTerraTrueColorCR, "2018-11-12"), ),
center=center,
zoom=4
)
m
In [ ]:
from ipyleaflet import Marker, Icon
icon = Icon(icon_url='https://leafletjs.com/examples/custom-icons/leaf-red.png', icon_size=[38, 95], icon_anchor=[22,94])
mark = Marker(location=center, icon=icon, rotation_origin='22px 94px')
m.add_layer(mark)
In [ ]:
import time
for _ in range(40):
mark.rotation_angle += 15
time.sleep(0.1)
pip install jupyterlab_sidecar
In [ ]:
from sidecar import Sidecar
from IPython.display import display
In [ ]:
sc = Sidecar(title='Map widget')
with sc:
display(m)
In [ ]:
from ipywidgets import Button, IntSlider, link
from ipyleaflet import Heatmap
from random import gauss
import time
In [ ]:
center = (37.09, -103.66)
zoom = 5
In [ ]:
def create_random_data(length):
"Return a list of some random lat/lon/value triples."
return [[gauss(center[0], 2),
gauss(center[1], 4),
gauss(700, 300)] for i in range(length)]
In [ ]:
m.center = center
m.zoom = zoom
In [ ]:
heat = Heatmap(locations=create_random_data(1000), radius=20, blur=10)
m.add_layer(heat)
In [ ]:
def generate(_):
heat.locations = create_random_data(1000)
button = Button(description='Generate data', button_style='success')
button.on_click(generate)
button
In [ ]:
slider = IntSlider(min=10, max=30, value=heat.radius)
link((slider, 'value'), (heat, 'radius'))
slider
In [ ]:
from ipyleaflet import Velocity
import xarray as xr
In [ ]:
center = (0, 0)
zoom = 4
m2 = Map(center=center, zoom=zoom, interpolation='nearest', basemap=basemaps.CartoDB.DarkMatter)
sc2 = Sidecar(title='Map Velocity')
with sc2:
display(m2)
In [ ]:
ds = xr.open_dataset('src/wind-global.nc')
display_options = {
'velocityType': 'Global Wind',
'displayPosition': 'bottomleft',
'displayEmptyString': 'No wind data'
}
wind = Velocity(data=ds,
zonal_speed='u_wind',
meridional_speed='v_wind',
latitude_dimension='lat',
longitude_dimension='lon',
velocity_scale=0.01,
max_velocity=20,
display_options=display_options)
m2.add_layer(wind)
In [ ]:
from ipyleaflet import Map, basemaps, basemap_to_tiles, SplitMapControl
m = Map(center=(42.6824, 365.581), zoom=5)
right_layer = basemap_to_tiles(basemaps.NASAGIBS.ModisTerraTrueColorCR, "2017-11-11")
left_layer = basemap_to_tiles(basemaps.NASAGIBS.ModisAquaBands721CR, "2017-11-11")
control = SplitMapControl(left_layer=left_layer, right_layer=right_layer)
m.add_control(control)
m
In [ ]:
import numpy as np
import bqplot.pyplot as plt
from bqplot import *
from traitlets import observe
from sidecar import Sidecar
from ipywidgets import VBox, Button
from ipyleaflet import Map, Marker, Popup
In [ ]:
axes_options = {'x': {'label': 'x'}, 'y': {'label': 'y'}}
x = np.arange(40)
y = np.cumsum(np.random.randn(2, 40), axis=1)
fig = plt.figure(animation_duration=1000)
lines = plt.plot(x=x, y=y, colors=['red', 'green'], axes_options=axes_options)
def generate(_):
lines.y = np.cumsum(np.random.randn(2, 40), axis=1)
button = Button(description='Generate data', button_style='success')
button.on_click(generate)
box_plot = VBox([fig, button])
fig
In [ ]:
center = (52.204793, 360.121558)
m = Map(center=center, zoom=9, close_popup_on_click=False)
marker = Marker(location=(52.1, 359.9))
m.add_layer(marker)
marker.popup = box_plot
sc = Sidecar(title='Map and bqplot')
with sc:
display(m)
In [ ]:
from ipywidgets import Widget
Widget.close_all()