<jupyter_start><jupyter_text>Simple Geographical Map<jupyter_code># general imports
import pandas as pd
import numpy as np

!pip install chart_studio

import json
import plotly.graph_objects as go
import chart_studio.plotly as py
from plotly.graph_objs import *
from google.colab import files

# here I used the API of plotly to visualize the data
# it's free to use but need sign up first
username = open(".username").read()
API = open(".API").read()
py.sign_in(username, API)
token = open(".mapbox_token").read()
global_df = pd.read_csv('Coronavirus_global.csv', thousands=',')
global_df = global_df.fillna(0)
"""Visualize Global Coronavirus Outbreak"""
"""
Compared to visualizing data of coronavirus outbreak in China,
visualize global data is much easier with the support of 
plotly functions.
"""

# data setting
global_data = Data([
    Choropleth(
    z = global_df.Diagnosed,
    colorbar = ColorBar(
        title='Number of People'
    ),
    colorscale=[[0, "rgb(255, 222, 156)"],
                [1./5000, "rgb(250,164,118)"],
                [1./2000, "rgb(240,116,110)"],
                [1./1000, "rgb(227,79,111)"],
                [1./500, "rgb(220,57,119)"],
                [1./100, "rgb(185,37,122)"],
                [1, "rgb(124, 29, 111)"]],
    hoverinfo='location+z',
    locationmode='country names',
    locations = global_df.Country,
    marker = Marker(
            line=Line(
                color='rgb(255,255,255)',
                width=2
            )
    ),
    text = global_df.Country
    )
])
# layout setting
layout = Layout(
    geo=dict(
        showframe=False,
        showcoastlines=False,
        projection_type='equirectangular'
    ),
    title='Global Coronavirus Map'
)

# show the plot
fig = Figure(data=global_data, layout=layout)
fig.show()

# This function will generate a plotly file to the plotly profile
# In this case, everyone can visit the map with a link
# For above graphs using data from China region
# This step is unavailable since the graphs generated is too big
plot_url1 = py.plot(fig)<jupyter_output><empty_output><jupyter_text>Time Series Map<jupyter_code>import pandas as pd
import numpy as np
import io

import plotly.express as ex
url = 'https://raw.githubusercontent.com/datasets/covid-19/master/data/countries-aggregated.csv'
df = pd.DataFrame(pd.read_csv(url))
df = df[df.Confirmed>0]
df
fig = ex.choropleth(df,
                    locations="Country", 
                    locationmode = "country names",
                    color="Confirmed", 
                    animation_frame="Date",
                    color_continuous_scale=ex.colors.sequential.Burg,
                    )
fig.update_layout(
    title_text = 'Global Coronavirus Outbreak (Confirmed)',
    title_x = 0.5,
    geo=dict(
        showframe = False,
        showcoastlines = False,
        projection_type='equirectangular'
    ))
    
fig.show()
plot_url2 = py.plot(fig) 


fig = ex.choropleth(df,
                    locations="Country", 
                    locationmode = "country names",
                    color="Deaths", 
                    animation_frame="Date",
                    color_continuous_scale=ex.colors.sequential.Greys
                    )
fig.update_layout(
    title_text = 'Global Coronavirus Outbreak (Deaths)',
    title_x = 0.5,
    geo=dict(
        showframe = False,
        showcoastlines = False,
        projection_type='equirectangular'
    ))
    
fig.show()
plot_url3 = py.plot(fig) 
fig = ex.choropleth(df,
                    locations="Country", 
                    locationmode = "country names",
                    color="Recovered", 
                    animation_frame="Date",
                    color_continuous_scale=ex.colors.sequential.Teal
                    )
fig.update_layout(
    title_text = 'Global Coronavirus Outbreak (Recovered)',
    title_x = 0.5,
    geo=dict(
        showframe = False,
        showcoastlines = False,
        projection_type='equirectangular'
    ))
    
fig.show()
plot_url4 = py.plot(fig) 
us_url = 'https://raw.githubusercontent.com/nytimes/covid-19-data/master/us-states.csv'
us_df = pd.DataFrame(pd.read_csv(us_url))
us_df = us_df[us_df.cases>0]
us_df = us_df.reset_index(drop=True)
us_df
states = {'Alabama': 'AL',
    'Alaska': 'AK',
    'American Samoa': 'AS',
    'Arizona': 'AZ',
    'Arkansas': 'AR',
    'California': 'CA',
    'Colorado': 'CO',
    'Connecticut': 'CT',
    'Delaware': 'DE',
    'District of Columbia': 'DC',
    'Florida': 'FL',
    'Georgia': 'GA',
    'Guam': 'GU',
    'Hawaii': 'HI',
    'Idaho': 'ID',
    'Illinois': 'IL',
    'Indiana': 'IN',
    'Iowa': 'IA',
    'Kansas': 'KS',
    'Kentucky': 'KY',
    'Louisiana': 'LA',
    'Maine': 'ME',
    'Maryland': 'MD',
    'Massachusetts': 'MA',
    'Michigan': 'MI',
    'Minnesota': 'MN',
    'Mississippi': 'MS',
    'Missouri': 'MO',
    'Montana': 'MT',
    'Nebraska': 'NE',
    'Nevada': 'NV',
    'New Hampshire': 'NH',
    'New Jersey': 'NJ',
    'New Mexico': 'NM',
    'New York': 'NY',
    'North Carolina': 'NC',
    'North Dakota': 'ND',
    'Northern Mariana Islands':'MP',
    'Ohio': 'OH',
    'Oklahoma': 'OK',
    'Oregon': 'OR',
    'Pennsylvania': 'PA',
    'Puerto Rico': 'PR',
    'Rhode Island': 'RI',
    'South Carolina': 'SC',
    'South Dakota': 'SD',
    'Tennessee': 'TN',
    'Texas': 'TX',
    'Utah': 'UT',
    'Vermont': 'VT',
    'Virgin Islands': 'VI',
    'Virginia': 'VA',
    'Washington': 'WA',
    'West Virginia': 'WV',
    'Wisconsin': 'WI',
    'Wyoming': 'WY'}

for i in range(len(us_df)):
  us_df.loc[i,'State']=states.get(us_df.loc[i].state)

fig = ex.choropleth(us_df, 
                    locations='State',
                    locationmode='USA-states',
                    color="cases", 
                    animation_frame="date",
                    hover_name = 'state',
                    color_continuous_scale=ex.colors.sequential.Burg,
                    scope='usa',
                    )
fig.update_layout(
    margin={"r":0,"t":0,"l":0,"b":0},
    title_text = 'USA Coronavirus Outbreak (Confirmed)',
    title_x = 0.5,
    geo=dict(
        showframe = False,
        showcoastlines = False,
    ))
    
fig.show()
plot_url5 = py.plot(fig)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1468989769820972, 'fraction_numerical': 0.018861892583120203, 'mean_word_length': 2.4284931506849317, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 11, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '613401', 'license': 'MIT', 'n_tokens_mistral': 2208, 'n_tokens_neox': 2033, 'n_words': 464, 'path': 'Visualization/Time Series Map Visualization.ipynb', 'repo_name': 'dalezys/Coronavirus_Data_Scrape_and_Visualization_2020', 'size': '6256'}