{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "![Callysto.ca Banner](https://github.com/callysto/curriculum-notebooks/blob/master/callysto-notebook-banner-top.jpg?raw=true)\n", "\n", "\"Open" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Communication and Globalization\n", "\n", "Advances in communication technology has made the world a global village. Digital gadgets such as computers and mobile phones have revolutionized the exchange of information, affecting global diversity, identity, and culture. With the internet providing access to vast amount of information, the effects of digital advances have become increasingly more swift and complex.\n", "\n", "Let's try to gauge the spread of digital advances around the world. The datasets from [Our World in Data](https://ourworldindata.org/internet) are used to visualize access to mobile phones, the internet, and social media platforms." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Internet access across the globe\n", "\n", "Let's check out the proportion of a population in a given country that has internet access. Run the following code cells to import the data and preview it." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Import Python libraries\n", "import pandas as pd\n", "import plotly_express as px\n", "import matplotlib.pyplot as plt\n", "import matplotlib.animation as animation\n", "from ipywidgets import interact, fixed, widgets, Layout, Button, Box, fixed, HBox, VBox\n", "from IPython.display import clear_output\n", "from IPython.display import HTML\n", "\n", "# Don't show warnings in output\n", "import warnings\n", "warnings.filterwarnings('ignore')\n", "print('Libraries successfully imported.')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Import the dataset\n", "df = pd.read_csv('./Data/share-of-individuals-using-the-internet.csv')\n", "\n", "# Data clean up - consider the data between 2001 and 2016\n", "df=df[df['Year'] > 2000][df['Year'] < 2017]\n", "\n", "# Display the bottom 5 rows\n", "df.tail()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Plot an animated choropleth map\n", "\n", "fig = px.choropleth(df, # dataframe with required data \n", " locations=\"Code\", # Column containing country codes\n", " color=\"Internet Access
(% of population)\", # Color of country should be based on internet access\n", " hover_name=\"Entity\", # Title to add to hover information\n", " hover_data=['Internet Access
(% of population)'], # Data to add to hover information\n", " color_continuous_scale=px.colors.sequential.Reds, # Set the colorscale type\n", " animation_frame = \"Year\", # Values based on which animation frame will be prepared\n", " range_color = [0,100], # Range of the colorbar\n", " \n", " # Title of the chart\n", " title = 'Population with internet access in various countries
\\\n", "Source: Our World in Data'\n", " )\n", "\n", "# Show the figure\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Hover your mouse over different countries on the choropleth map and see the share of population that has access to the internet.\n", "\n", "### Discussion Questions:\n", "\n", "1. Why do you think internet access is unequal among the countries in the world? \n", "2. How can we improve this [digital divide](https://en.wikipedia.org/wiki/Digital_divide)? Are you aware of any organizations working on this issue? \n", "3. Is high-speed internet access generally available in First Nations communities? Discuss the digital divide within Canada." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Mobile phone access across the globe\n", "\n", "Mobile (or cellular) phones have emerged as a disruptive digital technology due to their multiple uses and portability.\n", "\n", "Let's visualize how many people have access to this technology. Run the following code cells to import the dataset and plot an animated choropleth map." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Import the dataset\n", "df2 = pd.read_csv('./Data/mobile-cellular-subscriptions-per-100-people.csv')\n", "\n", "# Data clean up - consider the data from 1991\n", "df2=df2[df2['Year'] > 1990]\n", "\n", "# Show the bottom 5 rows\n", "df2.tail()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Plot animated choropleth map\n", "\n", "fig = px.choropleth(df2, # dataframe with required data \n", " locations=\"Code\", # Column containing country codes\n", " color=\"Cellular subscriptions
(per 100 people)\", # Color of country should be based on cellular subscriptions\n", " hover_name=\"Entity\", # Title to add to hover information\n", " hover_data=[\"Cellular subscriptions
(per 100 people)\"], # Data to add to hover information\n", " color_continuous_scale=px.colors.sequential.Reds, # Set the colorscale type\n", " animation_frame = \"Year\", # Values based on which animation frame will be prepared\n", " range_color = [0,200], # Range of the colorbar\n", " \n", " # Title of the chart\n", " title = 'Cellular subscriptions (per 100 people) around the world
\\\n", "Source: Our World in Data'\n", " )\n", "\n", "# Show the figure\n", "fig.show()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Questions:\n", "\n", "1. How does the availability of mobile phones compare to internet access?\n", "2. How can diversity or identity be affected by communication technologies such as mobile phones?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Are social media platforms changing the world?\n", "\n", "With the internet and mobile phones being increasingly integrated into our lives, the use of social media platforms is increasing. One in three people of the world's 7.7 billion population is using social media. \n", "\n", "Let's create a bar chart animation showing monthly active users by platform since 2003. Run the code cells below." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Import the dataset and remove an empty column\n", "df3 = pd.read_csv('./Data/users-by-social-media-platform.csv').drop('Code',1)\n", "\n", "# Data transformation - convert the monthly active users in billion\n", "df3['Monthly active users'] = df3['Monthly active users']/1000000000\n", "\n", "# Define the colors - to be used in bar chart\n", "colors = ['violet', 'tomato', 'chocolate', 'teal', 'forestgreen', 'dodgerblue',\\\n", " 'lightcoral', 'limegreen', 'darkorange', 'goldenrod']\n", "\n", "# Show the top 5 rows\n", "df3.head()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Define the function to draw a bar chart for a given year\n", "def draw_barchart(current_year,colors=colors):\n", " # Find rows in the dataset for a given year\n", " dff = df3[df3['Year'].eq(current_year)].sort_values(by='Monthly active users', ascending=True)\\\n", " .tail(top_x_platforms_slider.value)\n", " \n", " ax.clear() # Clear the figure (in case any plot exists already)\n", " ax.barh(dff['Entity'], dff['Monthly active users'],color=colors) # plot the horizontal bar chart\n", " dx = dff['Monthly active users'].max() / 200 # margin for the text in plot\n", " \n", " # Specify annotations for each row in the dataframe\n", " for i, (value, name) in enumerate(zip(dff['Monthly active users'], dff['Entity'])):\n", " ax.text(value-dx, i-0.12, name, ha='right', size=14, weight=600) # Text/formatting for the name of the social media platform\n", " ax.text(value+dx, i-0.12, \"{0:.3f} billion\".format(value), ha='left', size=14) # Text/formatting for monthly active users\n", " ax.text(1, 0.4, current_year, transform=ax.transAxes, color='#777777', size=46, ha='right', weight=800) # Text/formatting for the corresponding year\n", " ax.text(0, 1.06, 'Monthly active users (billion)', transform=ax.transAxes, size=14, color='#777777') # Specify y-axis title\n", " ax.xaxis.set_ticks_position('top') # Set position of x-ticks\n", " ax.tick_params(axis='x', colors='#777777', labelsize=14) # Set parameters for x-ticks\n", " ax.set_yticks([]) # Set empty y-ticks\n", " ax.set_xlim([0,2.5]) # Set x-axis limits\n", " ax.margins(0, 0.01) # Set margins\n", " ax.grid(which='major', axis='x', linestyle='-') # Set gridline properties\n", " ax.set_axisbelow(True) # Specify axis location\n", " ax.text(0, 1.15, 'Most used social media platforms (2004 to 2017)',\n", " transform=ax.transAxes, size=24, weight=600, ha='left', va='top') # Specify plot title\n", " plt.box(False) # Disable box surrounding the plot\n", "\n", "# Define a callback function for \"Show Bar Chart\" button\n", "def draw_barchart2(ev):\n", " clear_output(wait=True)\n", " \n", " # Define display order for the buttons and menus\n", " display(Box(children = [top_x_platforms_slider,show_button1], \\\n", " layout = Layout(display= 'flex', flex_flow= 'column', \\\n", " align_items= 'center', width='100%', \\\n", " justify_content = 'center')))\n", " \n", " global fig, ax # Set figure as a global object\n", " \n", " # Create an empty figure object with given size\n", " fig, ax = plt.subplots(figsize=(15, 8)) \n", " \n", " # Create animation - each frame shows data for one year\n", " animator = animation.FuncAnimation(fig, draw_barchart, frames=range(2002,2018),interval=750, repeat=False)\n", " ANI = HTML(animator.to_jshtml())\n", " plt.close()\n", " display(ANI)\n", "print('We have defined the functions draw_barchart and draw_barchart2.')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Run the cell below and select how many top social media platforms you want to see in the animation. Then click the `Show Animation` button." ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": false }, "outputs": [], "source": [ "# Layout for widgets\n", "box_layout = Layout(display='flex', flex_flow='row', align_items='center', width='100%', justify_content = 'center')\n", "style = {'description_width': 'initial'}\n", "\n", "# Create dropdown menu for Artist and slider for How Many Top Platforms\n", "top_x_platforms_slider = widgets.IntSlider(value = 5, min = 5, max = 10, description = \"Number of Top Platforms\", style = style)\n", "\n", "# Create Show Top Artists button and define click events\n", "show_button1 = widgets.Button(button_style= 'info', description=\"Show Animation\")\n", "show_button1.on_click(draw_barchart2)\n", "\n", "# Define display order for the buttons and menus\n", "display(Box(children = [top_x_platforms_slider,show_button1], layout = Layout(display= 'flex', flex_flow= 'column', align_items= 'center', width='100%', justify_content = 'center')))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Run the animation by clicking on the ▶ (play) button. \n", "\n", "### Discussion Questions:\n", "1. Based on the trend in recent years, do you think Whatsapp might soon have more users than YouTube?\n", "2. Discuss how social media use has changed people's sense of community and socialization practices. Do you think we are we becoming \"high-tech hermits\" or creating a new kind of social connection?" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "[![Callysto.ca License](https://github.com/callysto/curriculum-notebooks/blob/master/callysto-notebook-banner-bottom.jpg?raw=true)](https://github.com/callysto/curriculum-notebooks/blob/master/LICENSE.md)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.7.4" }, "nbTranslate": { "displayLangs": [ "*" ], "hotkey": "alt-t", "langInMainMenu": true, "sourceLang": "en", "targetLang": "fr", "useGoogleTranslate": true } }, "nbformat": 4, "nbformat_minor": 2 }