-
-
Notifications
You must be signed in to change notification settings - Fork 544
Choropleth Docs #879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Choropleth Docs #879
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
4dc9752
county_choropleth first draft
Coding-with-Adam 90d30d5
replaced broken choropleth-maps notebook
Coding-with-Adam 8b779b1
regenerated HTML for choroeplth-maps doc
Coding-with-Adam 5dff3c7
create mapbox-choropleth doc and chelsea's first round of comments fo…
Coding-with-Adam f73881e
hide mapbox doc page on main plotly/python page
Coding-with-Adam 80aedac
corrected redirect url
Coding-with-Adam d9e6755
change titles for maps docs
Coding-with-Adam 61bf711
2nd round of comments
Coding-with-Adam 448dd64
add mapbox back to index page
Coding-with-Adam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
223 changes: 95 additions & 128 deletions
223
_posts/python/maps/choropleth-maps/2015-06-30-Choropleth_maps.html
Large diffs are not rendered by default.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,20 +14,18 @@ | |
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### United States Choropleth Map" | ||
"#### United States Choropleth Map" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~chelsea_lyn/7898.embed\" height=\"525px\" width=\"100%\"></iframe>" | ||
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~AdamKulidjian/6694.embed\" height=\"525px\" width=\"100%\"></iframe>" | ||
], | ||
"text/plain": [ | ||
"<plotly.tools.PlotlyDisplay object>" | ||
|
@@ -89,20 +87,18 @@ | |
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### World Choropleth Map" | ||
"#### World Choropleth Map" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~chelsea_lyn/7903.embed\" height=\"525px\" width=\"100%\"></iframe>" | ||
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~AdamKulidjian/6696.embed\" height=\"525px\" width=\"100%\"></iframe>" | ||
], | ||
"text/plain": [ | ||
"<plotly.tools.PlotlyDisplay object>" | ||
|
@@ -160,20 +156,18 @@ | |
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Choropleth Inset Map" | ||
"#### Choropleth Inset Map" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~chelsea_lyn/13235.embed\" height=\"525px\" width=\"100%\"></iframe>" | ||
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~AdamKulidjian/6698.embed\" height=\"525px\" width=\"100%\"></iframe>" | ||
], | ||
"text/plain": [ | ||
"<plotly.tools.PlotlyDisplay object>" | ||
|
@@ -276,136 +270,81 @@ | |
")\n", | ||
"\n", | ||
"fig = go.Figure(layout=layout, data=cases+inset)\n", | ||
"py.iplot(fig, validate=False, filename='West Africa Ebola cases 2014')\n" | ||
"py.iplot(fig, validate=False, filename='West Africa Ebola cases 2014')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### PACE Approved Legislation " | ||
"#### Full County Choropleths\n", | ||
"For the full county choropleth doc page checkout https://plot.ly/python/county-choropleth/" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"The draw time for this plot will be slow for clients without much RAM.\n" | ||
] | ||
}, | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/plotly/api/v1/clientresp.py:40: UserWarning:\n", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you remove this warning from the docs?
in the beginning of your notebook ) |
||
"\n", | ||
"Estimated Draw Time Slow\n", | ||
"\n" | ||
] | ||
}, | ||
{ | ||
"data": { | ||
"text/html": [ | ||
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~Diksha_Gabha/2513.embed\" height=\"525px\" width=\"800px\"></iframe>" | ||
"<iframe id=\"igraph\" scrolling=\"no\" style=\"border:none;\" seamless=\"seamless\" src=\"https://plot.ly/~AdamKulidjian/6672.embed\" height=\"450px\" width=\"900px\"></iframe>" | ||
], | ||
"text/plain": [ | ||
"<plotly.tools.PlotlyDisplay object>" | ||
] | ||
}, | ||
"execution_count": 1, | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"import plotly.plotly as py\n", | ||
"from plotly.graph_objs import *\n", | ||
"import plotly.figure_factory as ff\n", | ||
"\n", | ||
"trace1 = Choropleth(\n", | ||
" z=['1', '1', '1', '1', '1', '1', '1'],\n", | ||
" autocolorscale=False,\n", | ||
" colorscale=[[0, 'rgb(255,255,255)'], [1, 'rgb(186,58,51)']],\n", | ||
" hoverinfo='text',\n", | ||
" locationmode='USA-states',\n", | ||
" locations=['AR', 'GA', 'KY', 'MO', 'UT', 'TX', 'WY'],\n", | ||
" name='Republican',\n", | ||
" showscale=False,\n", | ||
" text=['Arkansas', 'Georgia', 'Kentucky', 'Missouri', 'Utah', 'Texas', 'Wyoming'],\n", | ||
" zauto=False,\n", | ||
" zmax=1,\n", | ||
" zmin=0,\n", | ||
")\n", | ||
"trace2 = Choropleth(\n", | ||
" z=[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],\n", | ||
" autocolorscale=False,\n", | ||
" colorscale=[[0, 'rgb(255,255,255)'], [1, 'rgb(68,94,150)']],\n", | ||
" hoverinfo='text',\n", | ||
" locationmode='USA-states',\n", | ||
" locations=['CA', 'CI', 'DOC', 'IL', 'MD', 'NJ', 'NM', 'NY', 'OR', 'RI', 'VT'],\n", | ||
" name='Democrat',\n", | ||
" showscale=False,\n", | ||
" text=['California', 'Connecticut', 'District of Columbia', 'Illinois', \n", | ||
" 'Maryland', 'New Jersey', 'New Mexico', 'New York', 'Oregon',\n", | ||
" 'Rhode Island', 'Vermont'],\n", | ||
" zauto=False,\n", | ||
" zmax=1,\n", | ||
" zmin=0,\n", | ||
")\n", | ||
"trace3 = Choropleth(\n", | ||
" z=[1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],\n", | ||
" autocolorscale=False,\n", | ||
" colorscale=[[0, 'rgb(255, 255, 255)'], [1, 'rgb(187, 170, 144)']],\n", | ||
" hoverinfo='text',\n", | ||
" locationmode='USA-states',\n", | ||
" locations=['CO', 'FL', 'MI', 'MN', 'NH', 'OH', 'VA', 'WI'],\n", | ||
" name='Swing State',\n", | ||
" showscale=False,\n", | ||
" text=['Colorado', 'Florida', 'Michigan', 'Minnesota', \n", | ||
" 'New Hampshire', 'Ohio', 'Virginia', 'Wisconsin'],\n", | ||
" zauto=False,\n", | ||
" zmax=1,\n", | ||
" zmin=0,\n", | ||
")\n", | ||
"import numpy as np\n", | ||
"import pandas as pd\n", | ||
"\n", | ||
"data = Data([trace1, trace2, trace3])\n", | ||
"layout = Layout(\n", | ||
" autosize=False,\n", | ||
" geo=dict(\n", | ||
" countrycolor='rgb(102, 102, 102)',\n", | ||
" countrywidth=0.1,\n", | ||
" lakecolor='rgb(255, 255, 255)',\n", | ||
" landcolor='rgba(237, 247, 138, 0.28)',\n", | ||
" lonaxis=dict(\n", | ||
" gridwidth=1.5999999999999999,\n", | ||
" range=[-180, -50],\n", | ||
" showgrid=False\n", | ||
" ),\n", | ||
" projection=dict(\n", | ||
" type='albers usa'\n", | ||
" ),\n", | ||
" scope='usa',\n", | ||
" showland=True,\n", | ||
" showrivers=False,\n", | ||
" showsubunits=True,\n", | ||
" subunitcolor='rgb(102, 102, 102)',\n", | ||
" subunitwidth=0.5\n", | ||
" ),\n", | ||
" hovermode='closest',\n", | ||
" images=list([\n", | ||
" dict(\n", | ||
" x=1,\n", | ||
" y=0.6,\n", | ||
" sizex=0.155,\n", | ||
" sizey=0.4,\n", | ||
" source='http://i.imgur.com/Xe3f1zg.png',\n", | ||
" xanchor='right',\n", | ||
" xref='paper',\n", | ||
" yanchor='bottom',\n", | ||
" yref='paper'\n", | ||
" )\n", | ||
" ]),\n", | ||
" showlegend=True,\n", | ||
" title='<b>PACE Approved legislation</b>',\n", | ||
" width= 800,\n", | ||
" margin = dict(\n", | ||
" l=0,\n", | ||
" r=50,\n", | ||
" b=100,\n", | ||
" t=100,\n", | ||
" pad=4)\n", | ||
"df_sample = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/laucnty16.csv')\n", | ||
"df_sample['State FIPS Code'] = df_sample['State FIPS Code'].apply(lambda x: str(x).zfill(2))\n", | ||
"df_sample['County FIPS Code'] = df_sample['County FIPS Code'].apply(lambda x: str(x).zfill(3))\n", | ||
"df_sample['FIPS'] = df_sample['State FIPS Code'] + df_sample['County FIPS Code']\n", | ||
"\n", | ||
"colorscale = [\"#f7fbff\",\"#ebf3fb\",\"#deebf7\",\"#d2e3f3\",\"#c6dbef\",\"#b3d2e9\",\"#9ecae1\",\n", | ||
" \"#85bcdb\",\"#6baed6\",\"#57a0ce\",\"#4292c6\",\"#3082be\",\"#2171b5\",\"#1361a9\",\n", | ||
" \"#08519c\",\"#0b4083\",\"#08306b\"]\n", | ||
"endpts = list(np.linspace(1, 12, len(colorscale) - 1))\n", | ||
"fips = df_sample['FIPS'].tolist()\n", | ||
"values = df_sample['Unemployment Rate (%)'].tolist()\n", | ||
"\n", | ||
"fig = ff.create_choropleth(\n", | ||
" fips=fips, values=values, scope=['usa'],\n", | ||
" binning_endpoints=endpts, colorscale=colorscale,\n", | ||
" show_state_data=False,\n", | ||
" show_hover=True, centroid_marker={'opacity': 0},\n", | ||
" asp=2.9, title='USA by Unemployment %',\n", | ||
" legend_title='% unemployed'\n", | ||
")\n", | ||
"fig = Figure(data=data, layout=layout)\n", | ||
"py.iplot(fig, filename='pace')" | ||
"py.iplot(fig, filename='choropleth_full_usa')" | ||
] | ||
}, | ||
{ | ||
|
@@ -418,14 +357,8 @@ | |
}, | ||
{ | ||
"cell_type": "code", | ||
<<<<<<< HEAD | ||
"execution_count": 1, | ||
======= | ||
"execution_count": 2, | ||
>>>>>>> b22a31ab6cd91d151ab51741f3fcb448574008a5 | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
|
@@ -456,58 +389,22 @@ | |
"output_type": "stream", | ||
"text": [ | ||
"Collecting git+https://github.com/plotly/publisher.git\n", | ||
<<<<<<< HEAD | ||
" Cloning https://github.com/plotly/publisher.git to /var/folders/ld/6cl3s_l50wd40tdjq2b03jxh0000gp/T/pip-k8JnpP-build\n", | ||
" Cloning https://github.com/plotly/publisher.git to /private/var/folders/tc/bs9g6vrd36q74m5t8h9cgphh0000gn/T/pip-OKLJ7r-build\n", | ||
"Installing collected packages: publisher\n", | ||
" Found existing installation: publisher 0.11\n", | ||
" Uninstalling publisher-0.11:\n", | ||
" Successfully uninstalled publisher-0.11\n", | ||
" Running setup.py install for publisher ... \u001b[?25l-\b \b\\\b \bdone\n", | ||
"\u001b[?25hSuccessfully installed publisher-0.10\n" | ||
======= | ||
" Cloning https://github.com/plotly/publisher.git to /tmp/pip-ittp0v-build\n", | ||
"Installing collected packages: publisher\n", | ||
" Running setup.py install for publisher ... \u001b[?25l-\b \berror\n", | ||
" Complete output from command /usr/bin/python -u -c \"import setuptools, tokenize;__file__='/tmp/pip-ittp0v-build/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec'))\" install --record /tmp/pip-lGFm1Y-record/install-record.txt --single-version-externally-managed --compile:\n", | ||
" running install\n", | ||
" running build\n", | ||
" running build_py\n", | ||
" creating build\n", | ||
" creating build/lib.linux-x86_64-2.7\n", | ||
" creating build/lib.linux-x86_64-2.7/publisher\n", | ||
" copying publisher/publisher.py -> build/lib.linux-x86_64-2.7/publisher\n", | ||
" copying publisher/__init__.py -> build/lib.linux-x86_64-2.7/publisher\n", | ||
" running install_lib\n", | ||
" creating /usr/local/lib/python2.7/dist-packages/publisher\n", | ||
" error: could not create '/usr/local/lib/python2.7/dist-packages/publisher': Permission denied\n", | ||
" \n", | ||
" ----------------------------------------\n", | ||
"\u001b[31mCommand \"/usr/bin/python -u -c \"import setuptools, tokenize;__file__='/tmp/pip-ittp0v-build/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec'))\" install --record /tmp/pip-lGFm1Y-record/install-record.txt --single-version-externally-managed --compile\" failed with error code 1 in /tmp/pip-ittp0v-build/\u001b[0m\n", | ||
"\u001b[?25h" | ||
] | ||
}, | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"/home/diksha/anaconda2/lib/python2.7/site-packages/IPython/nbconvert.py:13: ShimWarning:\n", | ||
"\n", | ||
"The `IPython.nbconvert` package has been deprecated. You should import from nbconvert instead.\n", | ||
"\n", | ||
"/home/diksha/anaconda2/lib/python2.7/site-packages/publisher/publisher.py:53: UserWarning:\n", | ||
"\n", | ||
"Did you \"Save\" this notebook before running this command? Remember to save, always save.\n", | ||
"\n" | ||
>>>>>>> b22a31ab6cd91d151ab51741f3fcb448574008a5 | ||
" Running setup.py install for publisher ... \u001b[?25ldone\n", | ||
"\u001b[?25hSuccessfully installed publisher-0.11\n" | ||
] | ||
}, | ||
{ | ||
"name": "stderr", | ||
"output_type": "stream", | ||
"text": [ | ||
"/Users/brandendunbar/Desktop/test/venv/lib/python2.7/site-packages/IPython/nbconvert.py:13: ShimWarning: The `IPython.nbconvert` package has been deprecated. You should import from nbconvert instead.\n", | ||
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/IPython/nbconvert.py:13: ShimWarning: The `IPython.nbconvert` package has been deprecated since IPython 4.0. You should import from nbconvert instead.\n", | ||
" \"You should import from nbconvert instead.\", ShimWarning)\n", | ||
"/Users/brandendunbar/Desktop/test/venv/lib/python2.7/site-packages/publisher/publisher.py:53: UserWarning: Did you \"Save\" this notebook before running this command? Remember to save, always save.\n", | ||
"/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/publisher/publisher.py:53: UserWarning: Did you \"Save\" this notebook before running this command? Remember to save, always save.\n", | ||
" warnings.warn('Did you \"Save\" this notebook before running this command? '\n" | ||
] | ||
} | ||
|
@@ -521,14 +418,13 @@ | |
"! pip install git+https://github.com/plotly/publisher.git --upgrade\n", | ||
"import publisher\n", | ||
"publisher.publish(\n", | ||
" 'Choropleth_maps.ipynb', 'python/choropleth-maps/', 'Choropleth Maps | plotly',\n", | ||
" 'How to make Choropleth maps in Python with Plotly.',\n", | ||
" title = 'Choropleth Maps | plotly',\n", | ||
" name = 'Choropleth Maps',\n", | ||
" 'Choropleth_maps.ipynb', 'python/choropleth-maps/', 'Choropleth Maps',\n", | ||
" 'How to make choropleth maps in Python with Plotly.',\n", | ||
" title = 'Python Choropleth Maps | Plotly',\n", | ||
" has_thumbnail='true', thumbnail='thumbnail/choropleth.jpg', \n", | ||
" language='python', page_type='example_index',\n", | ||
" display_as='maps', order=1,\n", | ||
" ipynb= '~notebook_demo/55')" | ||
" language='python',\n", | ||
" display_as='maps', order=1, ipynb='~notebook_demo/55',\n", | ||
" uses_plotly_offline=False)" | ||
] | ||
}, | ||
{ | ||
|
@@ -542,7 +438,6 @@ | |
} | ||
], | ||
"metadata": { | ||
"anaconda-cloud": {}, | ||
"kernelspec": { | ||
"display_name": "Python 2", | ||
"language": "python", | ||
|
@@ -558,9 +453,9 @@ | |
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython2", | ||
"version": "2.7.10" | ||
"version": "2.7.12" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 0 | ||
"nbformat_minor": 1 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this warning is ok