{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "/Users/chengjun/anaconda/lib/python2.7/site-packages/folium-0.3.0.dev0-py2.7.egg/folium/__init__.pyc\n", "0.3.0.dev\n" ] } ], "source": [ "import folium, jinja2, vincent\n", "from IPython.display import IFrame\n", "from IPython.core.display import HTML\n", "print(folium.__file__)\n", "print(folium.__version__)" ] }, { "cell_type": "code", "execution_count": 66, "metadata": { "collapsed": true }, "outputs": [], "source": [ "import pickle\n", "\n", "node_pkl = open('/Users/chengjun/GitHub/cjc2016/data/nodeLoc30.pkl', 'rb')\n", "nodeLoc = pickle.load(node_pkl)\n", "node_pkl.close()\n", "\n", "edge_pkl = open('/Users/chengjun/GitHub/cjc2016/data/edgeLoc30.pkl', 'rb')\n", "edgeLoc = pickle.load(edge_pkl)\n", "edge_pkl.close()" ] }, { "cell_type": "code", "execution_count": 67, "metadata": { "collapsed": false }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "12296\n", "12181\n", "12064\n", "12196\n", "12202\n", "12340\n", "12347\n", "12092\n", "12100\n", "12230\n", "12407\n", "12238\n", "12112\n", "12241\n", "12370\n", "12243\n", "12372\n", "12245\n", "12122\n", "12124\n", "12261\n", "12136\n", "12010\n", "12014\n", "12274\n", "12023\n", "12156\n", "12285\n", "12158\n", "12287\n" ] } ], "source": [ "for i in edgeLoc: print i" ] }, { "cell_type": "code", "execution_count": 87, "metadata": { "collapsed": true }, "outputs": [], "source": [ "beijing = folium.Map(location=(39.90403,116.407526), zoom_start=10)\n" ] }, { "cell_type": "code", "execution_count": 88, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 88, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from folium.plugins import MarkerCluster\n", "locations = [j for n in nodeLoc.values() for j in n.values()]\n", "popups = ['{}'.format(loc) for loc in locations]\n", "beijing.add_children(MarkerCluster(locations=locations, popups=popups))" ] }, { "cell_type": "code", "execution_count": 89, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 89, "metadata": {}, "output_type": "execute_result" } ], "source": [ "from folium import plugins\n", "\n", "beijing.add_children(plugins.HeatMap(locations))" ] }, { "cell_type": "code", "execution_count": 90, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import matplotlib\n", "color_num = 30\n", "cmap = matplotlib.cm.get_cmap('jet',color_num)\n", "colors = [matplotlib.colors.rgb2hex(cmap(i)) for i in range(color_num)]" ] }, { "cell_type": "code", "execution_count": 91, "metadata": { "collapsed": true }, "outputs": [], "source": [ "#colors = ['blue','orange', 'red']\n", "for k, community in enumerate(edgeLoc):\n", " locations = edgeLoc[community]\n", " for loc in locations:\n", " line = folium.PolyLine(locations=loc, color=colors[k])\n", " beijing.add_children(line)" ] }, { "cell_type": "code", "execution_count": 92, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "
" ], "text/plain": [ "" ] }, "execution_count": 92, "metadata": {}, "output_type": "execute_result" } ], "source": [ "beijing" ] }, { "cell_type": "code", "execution_count": 84, "metadata": { "collapsed": true }, "outputs": [], "source": [ "beijing.save('/Users/chengjun/GitHub/cjc2016/vis/beijing_mobile_30_line.html')" ] }, { "cell_type": "code", "execution_count": 93, "metadata": { "collapsed": true }, "outputs": [], "source": [ "beijing.save('/Users/chengjun/GitHub/cjc2016/vis/beijing_mobile_30_heat.html')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.10" } }, "nbformat": 4, "nbformat_minor": 0 }