Skip to content

Commit

Permalink
Merge pull request #59 from dkedar7/docs
Browse files Browse the repository at this point in the history
New examples
  • Loading branch information
dkedar7 authored Feb 8, 2025
2 parents ee2108e + 78540e4 commit b0f9628
Show file tree
Hide file tree
Showing 7 changed files with 7,715 additions and 1 deletion.
2 changes: 1 addition & 1 deletion docs/Examples/05_water_indices_with_spyndex.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
}
],
"source": [
"data = pd.read_csv(\"assets/gaul_data.csv\")"
"data = pd.read_csv(\"https://raw.githubusercontent.com/dkedar7/fast_dash/docs/docs/Examples/assets/gaul_data.csv\")"
]
},
{
Expand Down
159 changes: 159 additions & 0 deletions docs/Examples/06_choropleth_maps.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"[![Open in colab](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/dkedar7/fast_dash/blob/docs/docs/Examples/06_choropleth_maps.ipynb)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook is optimized to run in Google Colab."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"import pandas as pd\n",
"import plotly.graph_objects as go\n",
"import numpy as np\n",
"\n",
"from urllib.request import urlopen\n",
"import json\n",
"\n",
"from fast_dash import fastdash, Graph"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Counties sample data\n",
"with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:\n",
" counties = json.load(response)\n",
"\n",
"counties_df = pd.read_csv(\"https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv\", dtype={\"fips\": str})\n",
"\n",
"# US Ag exports sample data\n",
"us_ag_exports_df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/2011_us_ag_exports.csv')\n",
"\n",
"for col in us_ag_exports_df.columns:\n",
" us_ag_exports_df[col] = us_ag_exports_df[col].astype(str)\n",
"\n",
"us_ag_exports_df['text'] = us_ag_exports_df['state'] + '<br>' + \\\n",
" 'Beef ' + us_ag_exports_df['beef'] + ' Dairy ' + us_ag_exports_df['dairy'] + '<br>' + \\\n",
" 'Fruits ' + us_ag_exports_df['total fruits'] + ' Veggies ' + us_ag_exports_df['total veggies'] + '<br>' + \\\n",
" 'Wheat ' + us_ag_exports_df['wheat'] + ' Corn ' + us_ag_exports_df['corn']"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"WARNING:root:Parsing function docstring is still an experimental feature. To reduce uncertainty, consider setting `about` to `False`.\n"
]
},
{
"data": {
"text/html": [
"\n",
" <iframe\n",
" width=\"100%\"\n",
" height=\"650\"\n",
" src=\"http://127.0.0.1:8080/\"\n",
" frameborder=\"0\"\n",
" allowfullscreen\n",
" \n",
" ></iframe>\n",
" "
],
"text/plain": [
"<IPython.lib.display.IFrame at 0x1de2282eca0>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"@fastdash(theme=\"flatly\")\n",
"def visualize_states_and_counties(a: int) -> (Graph, Graph):\n",
" \"\"\"\n",
" Fast Dash allows quick and easy visualization of various geographies.\\\n",
" This application plots states and counties using two differnent basemaps.\\\n",
" Reference: https://plotly.com/python/mapbox-county-choropleth/.\n",
" \"\"\"\n",
"\n",
" # Plotly-native graph map\n",
" fig = go.Figure(data=go.Choropleth(\n",
" locations=us_ag_exports_df['code'],\n",
" z=us_ag_exports_df['total exports'].astype(float),\n",
" locationmode='USA-states',\n",
" colorscale='Reds',\n",
" autocolorscale=False,\n",
" text=us_ag_exports_df['text'], # hover text\n",
" marker_line_color='white', # line markers between states\n",
" colorbar_title=\"Millions USD\"\n",
" ))\n",
"\n",
" fig.update_layout(\n",
" title_text='2011 US Agriculture Exports by State<br>(Hover for breakdown)',\n",
" geo = dict(\n",
" scope='usa',\n",
" projection=go.layout.geo.Projection(type = 'albers usa'),\n",
" showlakes=True, # lakes\n",
" lakecolor='rgb(255, 255, 255)'),\n",
" )\n",
" \n",
" plotly_express = fig\n",
"\n",
" # Mapbox graph map\n",
" fig = go.Figure(go.Choroplethmapbox(geojson=counties, locations=counties_df.fips, z=counties_df.unemp,\n",
" colorscale=\"Viridis\", zmin=0, zmax=12, marker_line_width=0))\n",
" fig.update_layout(mapbox_style=\"light\", mapbox_accesstoken=\"...\",\n",
" mapbox_zoom=3, mapbox_center = {\"lat\": 37.0902, \"lon\": -95.7129})\n",
" fig.update_layout(margin={\"r\":0,\"t\":0,\"l\":0,\"b\":0})\n",
" mapbox = fig\n",
" return plotly_express, mapbox"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.9.16"
}
},
"nbformat": 4,
"nbformat_minor": 4
}
Loading

0 comments on commit b0f9628

Please sign in to comment.