{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "0.3.0.dev\n" ] } ], "source": [ "import os\n", "import folium\n", "\n", "print(folium.__version__)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from branca.element import Figure\n", "\n", "lon, lat = -122.1889, 46.1991\n", "\n", "location = [lat, lon]\n", "\n", "zoom_start = 13\n", "\n", "tiles = 'OpenStreetMap'" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Using same width and height triggers the scroll bar" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "width, height = 480, 350\n", "\n", "fig = Figure(width=width, height=height)\n", "\n", "m = folium.Map(\n", " location=location,\n", " tiles=tiles,\n", " width=width,\n", " height=height,\n", " zoom_start=zoom_start\n", ")\n", "\n", "fig.add_child(m)\n", "\n", "fig.save(os.path.join('results', 'WidthHeight_0.html'))\n", "\n", "fig" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Can figure take relative sizes?" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "width, height = '100%', 350\n", "\n", "fig = Figure(width=width, height=height)\n", "\n", "m = folium.Map(\n", " location=location,\n", " tiles=tiles,\n", " width=width,\n", " height=height,\n", " zoom_start=zoom_start\n", ")\n", "\n", "fig.add_child(m)\n", "\n", "fig.save(os.path.join('results', 'WidthHeight_1.html'))\n", "\n", "fig" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# I guess not. (Well, it does make sense for a single HTML page, but not for iframes.)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "width, height = 480, '100%'\n", "\n", "fig = Figure(width=width, height=height)\n", "\n", "m = folium.Map(\n", " location=location,\n", " tiles=tiles,\n", " width=width,\n", " height=height,\n", " zoom_start=zoom_start\n", ")\n", "\n", "fig.add_child(m)\n", "\n", "fig.save(os.path.join('results', 'WidthHeight_2.html'))\n", "\n", "fig" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Not that Figure is interpreting this as 50px. We should raise something and be explicit on the docs." ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "width, height = '50%', '100%'\n", "\n", "fig = Figure(width=width, height=height)\n", "\n", "m = folium.Map(\n", " location=location,\n", " tiles=tiles,\n", " width=width,\n", " height=height,\n", " zoom_start=zoom_start\n", ")\n", "\n", "fig.add_child(m)\n", "\n", "fig.save(os.path.join('results', 'WidthHeight_3.html'))\n", "\n", "fig" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Cannot parse value 150.0 as '%'\n" ] } ], "source": [ "width, height = '150%', '100%'\n", "\n", "try:\n", " folium.Map(location=location, tiles=tiles,\n", " width=width, height=height, zoom_start=zoom_start)\n", "except ValueError as e:\n", " print(e)" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Cannot parse value '80p' as '%'\n" ] } ], "source": [ "width, height = '50%', '80p'\n", "\n", "try:\n", " folium.Map(location=location, tiles=tiles,\n", " width=width, height=height, zoom_start=zoom_start)\n", "except ValueError as e:\n", " print(e)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Cannot parse value -350.0 as 'px'\n" ] } ], "source": [ "width, height = width, height = 480, -350\n", "\n", "try:\n", " folium.Map(location=location, tiles=tiles,\n", " width=width, height=height, zoom_start=zoom_start)\n", "except ValueError as e:\n", " print(e)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Maybe we should recommend" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "width, height = 480, 350\n", "\n", "fig = Figure(width=width, height=height)\n", "\n", "m = folium.Map(\n", " location=location,\n", " tiles=tiles,\n", " width='100%',\n", " height='100%',\n", " zoom_start=zoom_start\n", ")\n", "\n", "fig.add_child(m)\n", "\n", "fig.save(os.path.join('results', 'WidthHeight_4.html'))\n", "\n", "fig" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.2" } }, "nbformat": 4, "nbformat_minor": 0 }