|
1264 | 1264 | "<p>The interactivity works best in a notebook environment – here's an example of the slider, tooltips, and zoom/pan functionality in action:</p>\n", |
1265 | 1265 | "\n", |
1266 | 1266 | "<div style=\"text-align: center;\">\n", |
1267 | | - " <img width=\"50%\" src=\"https://raw.githubusercontent.com/stefmolin/python-data-viz-workshop/main/media/interactive_map.gif\" style=\"border: 5px solid #555; min-width: 600px;\">\n", |
| 1267 | + " <img width=\"50%\" src=\"media/interactive_map.gif\" style=\"border: 5px solid #555; min-width: 600px;\">\n", |
1268 | 1268 | "</div>" |
1269 | 1269 | ] |
1270 | 1270 | }, |
|
2268 | 2268 | "<p>The result can be interacted with after displaying it, but this kind of interactivity only works in the notebook. Here's an example:</p>\n", |
2269 | 2269 | "\n", |
2270 | 2270 | "<div style=\"text-align: center;\">\n", |
2271 | | - " <img alt=\"Linked plots example\" width=\"60%\" src=\"https://raw.githubusercontent.com/stefmolin/python-data-viz-workshop/main/media/linked_plots.gif\" style=\"border: 5px solid #555; min-width: 800px; margin: 0px auto;\">\n", |
| 2271 | + " <img alt=\"Linked plots example\" width=\"60%\" src=\"media/linked_plots.gif\" style=\"border: 5px solid #555; min-width: 800px; margin: 0px auto;\">\n", |
2272 | 2272 | " <br/>\n", |
2273 | 2273 | " <small><em>This example uses tabs to display the layout rather than side by side like we did. Tabs are a little buggy in this version, so we didn't use them.</em></small>\n", |
2274 | 2274 | "</div>" |
|
3309 | 3309 | "metadata": {}, |
3310 | 3310 | "source": [ |
3311 | 3311 | "<div style=\"text-align: center;\">\n", |
3312 | | - " <img width=\"50%\" src=\"https://raw.githubusercontent.com/stefmolin/python-data-viz-workshop/main/media/solution-3-1.gif\" style=\"border: 5px solid #555; min-width: 700px;\">\n", |
| 3312 | + " <img width=\"50%\" src=\"media/solution-3-1.gif\" style=\"border: 5px solid #555; min-width: 700px;\">\n", |
3313 | 3313 | "</div>" |
3314 | 3314 | ] |
3315 | 3315 | }, |
|
3353 | 3353 | }, |
3354 | 3354 | "source": [ |
3355 | 3355 | "<div style=\"text-align: center;\">\n", |
3356 | | - " <img width=\"75%\" src=\"https://raw.githubusercontent.com/stefmolin/python-data-viz-workshop/main/media/sankey_and_chord.png\" style=\"min-width: 750px\">\n", |
| 3356 | + " <img width=\"75%\" src=\"media/sankey_and_chord.png\" style=\"min-width: 750px\">\n", |
3357 | 3357 | "</div>" |
3358 | 3358 | ] |
3359 | 3359 | }, |
|
3384 | 3384 | "flight_stats = pd.read_csv(\n", |
3385 | 3385 | " '../data/T100_MARKET_ALL_CARRIER.zip',\n", |
3386 | 3386 | " usecols=[\n", |
3387 | | - " 'CLASS', 'REGION', 'UNIQUE_CARRIER_NAME', 'ORIGIN_CITY_NAME', 'ORIGIN', \n", |
| 3387 | + " 'CLASS', 'REGION', 'UNIQUE_CARRIER_NAME', 'ORIGIN_CITY_NAME', 'ORIGIN',\n", |
3388 | 3388 | " 'DEST_CITY_NAME', 'DEST', 'PASSENGERS', 'FREIGHT', 'MAIL'\n", |
3389 | 3389 | " ]\n", |
3390 | 3390 | ").rename(lambda x: x.lower(), axis=1).assign(\n", |
3391 | 3391 | " region=lambda x: x.region.replace({\n", |
3392 | | - " 'D': 'Domestic', 'I': 'International', 'A': 'Atlantic', \n", |
| 3392 | + " 'D': 'Domestic', 'I': 'International', 'A': 'Atlantic',\n", |
3393 | 3393 | " 'L': 'Latin America', 'P': 'Pacific', 'S': 'System'\n", |
3394 | 3394 | " }),\n", |
3395 | 3395 | " route=lambda x: np.where(\n", |
|
3594 | 3594 | "source": [ |
3595 | 3595 | "cities = [\n", |
3596 | 3596 | " 'Atlanta, GA', 'Chicago, IL', 'New York, NY', 'Los Angeles, CA',\n", |
3597 | | - " 'Dallas/Fort Worth, TX', 'Denver, CO', 'Houston, TX', \n", |
| 3597 | + " 'Dallas/Fort Worth, TX', 'Denver, CO', 'Houston, TX',\n", |
3598 | 3598 | " 'San Francisco, CA', 'Seattle, WA', 'Orlando, FL'\n", |
3599 | 3599 | "]\n", |
3600 | 3600 | "\n", |
|
3621 | 3621 | "A **chord diagram** is a way of showing many-to-many relationships between a set of entities called **nodes**: the nodes are arranged in a circle, and chords (which can be thought of as **edges**) are drawn between those that are connected, with the width of the chord encoding the strength of the connection. In this section, we will be making a chord diagram for total passenger service travel between the top 10 cities in 2019:\n", |
3622 | 3622 | "\n", |
3623 | 3623 | "<div style=\"text-align: center;\">\n", |
3624 | | - " <img width=\"35%\" src=\"https://raw.githubusercontent.com/stefmolin/python-data-viz-workshop/main/media/chord.png\" style=\"border: 5px solid #555; min-width: 350px\">\n", |
| 3624 | + " <img width=\"35%\" src=\"media/chord.png\" style=\"border: 5px solid #555; min-width: 350px\">\n", |
3625 | 3625 | "</div>" |
3626 | 3626 | ] |
3627 | 3627 | }, |
|
3891 | 3891 | "source": [ |
3892 | 3892 | "chord = hv.Chord(\n", |
3893 | 3893 | " total_flight_stats,\n", |
3894 | | - " kdims=['origin', 'dest'], \n", |
| 3894 | + " kdims=['origin', 'dest'],\n", |
3895 | 3895 | " vdims=['passengers', 'origin_city_name', 'dest_city_name', 'mail', 'freight']\n", |
3896 | 3896 | ")" |
3897 | 3897 | ] |
|
4105 | 4105 | "<p>The result can be interacted with after displaying it, but it works best in the notebook – the GIF below shows some example interactions. Note that for this visualization the interactivity is what makes it useful:</p>\n", |
4106 | 4106 | "\n", |
4107 | 4107 | "<div style=\"text-align: center;\">\n", |
4108 | | - " <img width=\"50%\" src=\"https://raw.githubusercontent.com/stefmolin/python-data-viz-workshop/main/media/chord.gif\" style=\"border: 5px solid #555; min-width: 500px;\">\n", |
| 4108 | + " <img width=\"50%\" src=\"media/chord.gif\" style=\"border: 5px solid #555; min-width: 500px;\">\n", |
4109 | 4109 | "</div>" |
4110 | 4110 | ] |
4111 | 4111 | }, |
|
4126 | 4126 | "For our final visualization, we will create a **Sankey plot**, which is a way to visualize flow as edges between nodes. Here, we will use it to analyze airline market share for passenger service flights between the top 5 US cities:\n", |
4127 | 4127 | "\n", |
4128 | 4128 | "<div style=\"text-align: center;\">\n", |
4129 | | - " <img width=\"50%\" src=\"https://raw.githubusercontent.com/stefmolin/python-data-viz-workshop/main/media/sankey.png\" style=\"border: 5px solid #555; min-width: 600px;\">\n", |
| 4129 | + " <img width=\"50%\" src=\"media/sankey.png\" style=\"border: 5px solid #555; min-width: 600px;\">\n", |
4130 | 4130 | "</div>" |
4131 | 4131 | ] |
4132 | 4132 | }, |
|
4550 | 4550 | ], |
4551 | 4551 | "source": [ |
4552 | 4552 | "carrier_edges = get_edges(\n", |
4553 | | - " domestic_passenger_travel, \n", |
| 4553 | + " domestic_passenger_travel,\n", |
4554 | 4554 | " source_col='region',\n", |
4555 | 4555 | " target_col='unique_carrier_name'\n", |
4556 | 4556 | ").replace('^Domestic$', 'Top Routes', regex=True)\n", |
|
4751 | 4751 | "outputs": [], |
4752 | 4752 | "source": [ |
4753 | 4753 | "sankey = hv.Sankey(\n", |
4754 | | - " all_edges, \n", |
| 4754 | + " all_edges,\n", |
4755 | 4755 | " kdims=['source', 'target'],\n", |
4756 | 4756 | " vdims=hv.Dimension('passengers', unit='M')\n", |
4757 | 4757 | ").opts(\n", |
4758 | | - " labels='index', label_position='right', cmap='Set1', # node config \n", |
| 4758 | + " labels='index', label_position='right', cmap='Set1', # node config\n", |
4759 | 4759 | " edge_color='lightgray', # edge config\n", |
4760 | 4760 | " width=750, height=600, # plot size config\n", |
4761 | 4761 | " title='Travel Between the Top 5 Cities in 2019'\n", |
|
4896 | 4896 | "<p>The resulting visualization can be interacted with after displaying it, but it works best in the notebook. Here's an example:</p>\n", |
4897 | 4897 | "\n", |
4898 | 4898 | "<div style=\"text-align: center;\">\n", |
4899 | | - " <img width=\"50%\" src=\"https://raw.githubusercontent.com/stefmolin/python-data-viz-workshop/main/media/sankey.gif\" style=\"border: 5px solid #555; min-width: 700px;\">\n", |
| 4899 | + " <img width=\"50%\" src=\"media/sankey.gif\" style=\"border: 5px solid #555; min-width: 700px;\">\n", |
4900 | 4900 | "</div>" |
4901 | 4901 | ] |
4902 | 4902 | }, |
|
5861 | 5861 | "metadata": {}, |
5862 | 5862 | "source": [ |
5863 | 5863 | "<div style=\"text-align: center;\">\n", |
5864 | | - " <img width=\"50%\" src=\"https://raw.githubusercontent.com/stefmolin/python-data-viz-workshop/main/media/solution-3-2.gif\" style=\"border: 5px solid #555; min-width: 700px;\">\n", |
| 5864 | + " <img width=\"50%\" src=\"media/solution-3-2.gif\" style=\"border: 5px solid #555; min-width: 700px;\">\n", |
5865 | 5865 | "</div>" |
5866 | 5866 | ] |
5867 | 5867 | }, |
|
5941 | 5941 | "*All examples herein were developed exclusively for this workshop – be sure to check out my book, [Hands-On Data Analysis with Pandas](https://www.amazon.com/Hands-Data-Analysis-Pandas-visualization-dp-1800563450/dp/1800563450/), and my [pandas workshop](https://stefaniemolin.com/workshops/pandas-workshop/) for more Python data science content.*\n", |
5942 | 5942 | "\n", |
5943 | 5943 | "<div style=\"text-align: center;\">\n", |
5944 | | - " <img width=\"20%\" src=\"https://raw.githubusercontent.com/stefmolin/Hands-On-Data-Analysis-with-Pandas-2nd-edition/master/_img/pandas_drawing.PNG\" style=\"min-width: 200px\">\n", |
| 5944 | + " <img width=\"20%\" src=\"media/pandas_drawing.png\" style=\"min-width: 200px\">\n", |
5945 | 5945 | " <div><small>\n", |
5946 | 5946 | " <a href=\"https://stefaniemolin.com\">stefaniemolin.com</a>\n", |
5947 | 5947 | " </small></div>\n", |
|
0 commit comments