Skip to content

Commit 5a4bf93

Browse files
author
Martin Journois
committed
Create Figure.add_subplot
1 parent 046976b commit 5a4bf93

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

folium/features.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,26 @@ def _repr_html_(self, figsize=(17,10), **kwargs):
217217
)
218218
return iframe
219219

220+
def add_subplot(self, x,y,n,margin=0.05):
221+
width = 1./y
222+
height = 1./x
223+
left = ((n-1)%y)*width
224+
top = ((n-1)//y)*height
225+
226+
left = left+width*margin
227+
top = top+height*margin
228+
width = width*(1-2.*margin)
229+
height = height*(1-2.*margin)
230+
231+
div = Div(position='absolute',
232+
width="{}%".format(100.*width),
233+
height="{}%".format(100.*height),
234+
left="{}%".format(100.*left),
235+
top="{}%".format(100.*top),
236+
)
237+
self.add_children(div)
238+
return div
239+
220240
class Link(Element):
221241
def get_code(self):
222242
if self.code is None:
@@ -426,12 +446,13 @@ def render(self, **kwargs):
426446

427447
def _parse_size(value):
428448
try:
429-
if isinstance(value, int):
449+
if isinstance(value, int) or isinstance(value, float):
430450
value_type = 'px'
451+
value = float(value)
431452
assert value > 0
432453
else:
433454
value_type = '%'
434-
value = int(value.strip('%'))
455+
value = float(value.strip('%'))
435456
assert 0 <= value <= 100
436457
except:
437458
msg = "Cannot parse value {!r} as {!r}".format

0 commit comments

Comments
 (0)