ipylayout
#
ipylayout
is based on GoldenLayout, a multi-screen layout manager for web applications.
Installation#
ipylayout
can be easily installed with pipenv:
$ pipenv install ipylayout
Installing ipylayout…
…
If not already done, ipywidgets
will also be installed.
Example#
For the following example you also need the Python packages ipyleaflet
and ipympl
.
[1]:
%matplotlib widget
import ipylayout
import ipywidgets
import ipyleaflet
import matplotlib.pyplot as plt
import numpy as np
plt.ioff()
[2]:
# create a plot
fig = plt.figure()
fig.canvas.header_visible = False
fig.canvas.layout.min_height = '300px'
fig.canvas.layout.width = '100%'
plt.title('Plotting: y=sin(x)')
x = np.linspace(0, 20, 500)
lines = plt.plot(x, np.sin(x))
[3]:
# create a slider
slider = ipywidgets.FloatSlider()
[4]:
# create a map
m = ipyleaflet.Map(
center=(52.204793, 360.121558),
zoom=4
)
[5]:
# create a layout
l = ipylayout.Layout(layout=ipywidgets.Layout(width='100%', height='800px'))
l.theme = 'light' # light or dark
l.config = {
'content': [{
'type': 'row',
'content': [{
'type': 'component',
'componentName': 'name0',
'componentState': { 'label': 'A' }
}, {
'type': 'column',
'content': [{
'type': 'component',
'componentName': 'name1',
'componentState': { 'label': 'B' }
}, {
'type': 'component',
'componentName': 'name2',
'componentState': { 'label': 'C' }
}]
}]
}]
}
l.components = {'name0': slider, 'name1': m, 'name2': fig.canvas}
[6]:
l
ipylayout
can also be used together with Voilà: