Created
August 13, 2021 03:05
-
-
Save giswqs/09f5cadc3dd0a7d0d56cacda987a80e1 to your computer and use it in GitHub Desktop.
ipysheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "import leafmap\nimport ipysheet\nimport ipyleaflet\nimport numpy as np\nimport bqplot.pyplot as plt\nimport ipywidgets as widgets", | |
"execution_count": 1, | |
"outputs": [] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "Create a sheet for hosting the map." | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "host = ipysheet.sheet(rows=2, columns=2)\nhost", | |
"execution_count": 2, | |
"outputs": [ | |
{ | |
"output_type": "display_data", | |
"data": { | |
"text/plain": "Sheet(columns=2, layout=Layout(height='auto', width='auto'), rows=2)", | |
"application/vnd.jupyter.widget-view+json": { | |
"version_major": 2, | |
"version_minor": 0, | |
"model_id": "a595c3959e1a414a8ac03b91b632bf29" | |
} | |
}, | |
"metadata": {} | |
} | |
] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "Create an interactive map." | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "m = leafmap.Map(draw_control=False, measure_control=False)\nm.add_basemap('Esri.NatGeoWorldMap')", | |
"execution_count": 3, | |
"outputs": [] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "Put the map in a cell." | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "map_cell = ipysheet.cell(0, 0, m, style={'min-width': '600px'})", | |
"execution_count": 4, | |
"outputs": [] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "Create sliders." | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "width_slider = widgets.IntSlider(value=925, min=0, max=925, layout=widgets.Layout(width='925px'))\nheight_slider = widgets.IntSlider(value=600, min=0, max=600, orientation='vertical',layout=widgets.Layout(height='600px'))", | |
"execution_count": 5, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "checkbox = widgets.Checkbox(description=\"Plot\", indent=False)\nchk_cell = ipysheet.cell(1, 1, checkbox)", | |
"execution_count": 6, | |
"outputs": [] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "Put a slider in a cell." | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "width_cell = ipysheet.cell(1, 0, width_slider, style={'min-width': '600px'})\nheight_cell = ipysheet.cell(0, 1, height_slider)", | |
"execution_count": 7, | |
"outputs": [] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "Create a plot." | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "size = 18\nscale = 100.\nnp.random.seed(0)\nx_data = np.arange(size)\ny_data = np.cumsum(np.random.randn(size) * scale)\n\nfig = plt.figure()\naxes_options = {'x': {'label': 'Date', 'tick_format': '%m/%d'},\n 'y': {'label': 'Price', 'tick_format': '0.0f'}}\n\nscatt = plt.scatter(x_data, y_data, colors=['red'], stroke='black')\nfig.layout.width=\"450px\"\n\nhbox = widgets.HBox()", | |
"execution_count": 8, | |
"outputs": [] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "Observe slider changes." | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "def change_width(change):\n if change[\"new\"]:\n m.layout.width = str(width_slider.value) + \"px\"\nwidth_slider.observe(change_width)", | |
"execution_count": 9, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "def change_height(change):\n if change[\"new\"]:\n m.layout.height = str(height_slider.value) + \"px\"\nheight_slider.observe(change_height)", | |
"execution_count": 10, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "def chk_change(change):\n if checkbox.value:\n hbox.children = [fig]\n else:\n hbox.children = []\ncheckbox.observe(chk_change)", | |
"execution_count": 11, | |
"outputs": [] | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "Add plot to the map." | |
}, | |
{ | |
"metadata": { | |
"trusted": true | |
}, | |
"cell_type": "code", | |
"source": "data_control = ipyleaflet.WidgetControl(widget=hbox, position=\"bottomright\")\nm.add_control(data_control)", | |
"execution_count": 12, | |
"outputs": [] | |
} | |
], | |
"metadata": { | |
"hide_input": false, | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3", | |
"language": "python" | |
}, | |
"language_info": { | |
"name": "python", | |
"version": "3.8.5", | |
"mimetype": "text/x-python", | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"pygments_lexer": "ipython3", | |
"nbconvert_exporter": "python", | |
"file_extension": ".py" | |
}, | |
"toc": { | |
"nav_menu": {}, | |
"number_sections": true, | |
"sideBar": true, | |
"skip_h1_title": false, | |
"base_numbering": 1, | |
"title_cell": "Table of Contents", | |
"title_sidebar": "Contents", | |
"toc_cell": false, | |
"toc_position": {}, | |
"toc_section_display": true, | |
"toc_window_display": false | |
}, | |
"varInspector": { | |
"window_display": false, | |
"cols": { | |
"lenName": 16, | |
"lenType": 16, | |
"lenVar": 40 | |
}, | |
"kernels_config": { | |
"python": { | |
"library": "var_list.py", | |
"delete_cmd_prefix": "del ", | |
"delete_cmd_postfix": "", | |
"varRefreshCmd": "print(var_dic_list())" | |
}, | |
"r": { | |
"library": "var_list.r", | |
"delete_cmd_prefix": "rm(", | |
"delete_cmd_postfix": ") ", | |
"varRefreshCmd": "cat(var_dic_list()) " | |
} | |
}, | |
"types_to_exclude": [ | |
"module", | |
"function", | |
"builtin_function_or_method", | |
"instance", | |
"_Feature" | |
] | |
}, | |
"gist": { | |
"id": "", | |
"data": { | |
"description": "ipysheet", | |
"public": true | |
} | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment