{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "
\n", " \n", "
\n", "\n", "# Utilizando Python para Analisar Dados sobre a Pandemia Covid-19 - Part 2\n", "## Renato Profeta \n", "### @Guitars.AI\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "hide_input": true }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%html\n", "" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Download dos Dados" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "hide_input": true }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%html\n", "" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "import requests" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "url = 'https://coronavirus-tracker-api.herokuapp.com/v2/locations?timelines=1'\n", "r = requests.get(url)\n", "print(type(r))" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "### API (Application Programming Interface)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ " - Interface de Programação de Aplicação\n", " - Ferramenta de comunicação entre aplicações que desejam compartilhar suas serviços, protocolos, rotinas.\n", " - Disponibiliar recurso de uma aplicação para ser utilizado por outras aplicações." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "#### Web API" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " - Interface de Programação de Aplicação para um servidor ou navegador web.\n", " - Aplicação Web Servidor-Cliente.\n", " - Mensagens de aquisição e resposta HTTP.\n", " - Geralmente nos formatos XML e JSON.\n", " " ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "hide_input": true }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%html\n", "" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n" ] } ], "source": [ "# Python Dictionary\n", "r=r.json()\n", "print(type(r))" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "df = pd.DataFrame(r['locations']).set_index('country')" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "### Dictionário" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ " - Estrutuda de dados para guardar grupos de objetos.\n", " - Composto por Keys : Values\n", " - Um tipo de mapeamento." ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "### Python Dictionary" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "hide_input": true, "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%html\n", "" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "### Apenas Informações Desejadas" ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
timelines
country
Thailand{'confirmed': {'latest': 411, 'timeline': {'20...
Japan{'confirmed': {'latest': 1007, 'timeline': {'2...
Singapore{'confirmed': {'latest': 432, 'timeline': {'20...
Nepal{'confirmed': {'latest': 1, 'timeline': {'2020...
Malaysia{'confirmed': {'latest': 1183, 'timeline': {'2...
\n", "
" ], "text/plain": [ " timelines\n", "country \n", "Thailand {'confirmed': {'latest': 411, 'timeline': {'20...\n", "Japan {'confirmed': {'latest': 1007, 'timeline': {'2...\n", "Singapore {'confirmed': {'latest': 432, 'timeline': {'20...\n", "Nepal {'confirmed': {'latest': 1, 'timeline': {'2020...\n", "Malaysia {'confirmed': {'latest': 1183, 'timeline': {'2..." ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data = pd.DataFrame(df['timelines'])\n", "data.head()" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "### Apenas Países Desejados" ] }, { "cell_type": "code", "execution_count": 17, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "countries = ['Latvia','Italy', 'Germany', 'Spain', 'Brazil']\n", "data=data.loc[countries,: ]\n" ] }, { "cell_type": "code", "execution_count": 18, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
timelines
country
Latvia{'confirmed': {'latest': 124, 'timeline': {'20...
Italy{'confirmed': {'latest': 53578, 'timeline': {'...
Germany{'confirmed': {'latest': 22213, 'timeline': {'...
Spain{'confirmed': {'latest': 25374, 'timeline': {'...
Brazil{'confirmed': {'latest': 1021, 'timeline': {'2...
\n", "
" ], "text/plain": [ " timelines\n", "country \n", "Latvia {'confirmed': {'latest': 124, 'timeline': {'20...\n", "Italy {'confirmed': {'latest': 53578, 'timeline': {'...\n", "Germany {'confirmed': {'latest': 22213, 'timeline': {'...\n", "Spain {'confirmed': {'latest': 25374, 'timeline': {'...\n", "Brazil {'confirmed': {'latest': 1021, 'timeline': {'2..." ] }, "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.head()" ] }, { "cell_type": "code", "execution_count": 19, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/plain": [ "{'latest': 53578,\n", " 'timeline': {'2020-01-22T00:00:00Z': 0,\n", " '2020-01-23T00:00:00Z': 0,\n", " '2020-01-24T00:00:00Z': 0,\n", " '2020-01-25T00:00:00Z': 0,\n", " '2020-01-26T00:00:00Z': 0,\n", " '2020-01-27T00:00:00Z': 0,\n", " '2020-01-28T00:00:00Z': 0,\n", " '2020-01-29T00:00:00Z': 0,\n", " '2020-01-30T00:00:00Z': 0,\n", " '2020-01-31T00:00:00Z': 2,\n", " '2020-02-01T00:00:00Z': 2,\n", " '2020-02-02T00:00:00Z': 2,\n", " '2020-02-03T00:00:00Z': 2,\n", " '2020-02-04T00:00:00Z': 2,\n", " '2020-02-05T00:00:00Z': 2,\n", " '2020-02-06T00:00:00Z': 2,\n", " '2020-02-07T00:00:00Z': 3,\n", " '2020-02-08T00:00:00Z': 3,\n", " '2020-02-09T00:00:00Z': 3,\n", " '2020-02-10T00:00:00Z': 3,\n", " '2020-02-11T00:00:00Z': 3,\n", " '2020-02-12T00:00:00Z': 3,\n", " '2020-02-13T00:00:00Z': 3,\n", " '2020-02-14T00:00:00Z': 3,\n", " '2020-02-15T00:00:00Z': 3,\n", " '2020-02-16T00:00:00Z': 3,\n", " '2020-02-17T00:00:00Z': 3,\n", " '2020-02-18T00:00:00Z': 3,\n", " '2020-02-19T00:00:00Z': 3,\n", " '2020-02-20T00:00:00Z': 3,\n", " '2020-02-21T00:00:00Z': 20,\n", " '2020-02-22T00:00:00Z': 62,\n", " '2020-02-23T00:00:00Z': 155,\n", " '2020-02-24T00:00:00Z': 229,\n", " '2020-02-25T00:00:00Z': 322,\n", " '2020-02-26T00:00:00Z': 453,\n", " '2020-02-27T00:00:00Z': 655,\n", " '2020-02-28T00:00:00Z': 888,\n", " '2020-02-29T00:00:00Z': 1128,\n", " '2020-03-01T00:00:00Z': 1694,\n", " '2020-03-02T00:00:00Z': 2036,\n", " '2020-03-03T00:00:00Z': 2502,\n", " '2020-03-04T00:00:00Z': 3089,\n", " '2020-03-05T00:00:00Z': 3858,\n", " '2020-03-06T00:00:00Z': 4636,\n", " '2020-03-07T00:00:00Z': 5883,\n", " '2020-03-08T00:00:00Z': 7375,\n", " '2020-03-09T00:00:00Z': 9172,\n", " '2020-03-10T00:00:00Z': 10149,\n", " '2020-03-11T00:00:00Z': 12462,\n", " '2020-03-12T00:00:00Z': 12462,\n", " '2020-03-13T00:00:00Z': 17660,\n", " '2020-03-14T00:00:00Z': 21157,\n", " '2020-03-15T00:00:00Z': 24747,\n", " '2020-03-16T00:00:00Z': 27980,\n", " '2020-03-17T00:00:00Z': 31506,\n", " '2020-03-18T00:00:00Z': 35713,\n", " '2020-03-19T00:00:00Z': 41035,\n", " '2020-03-20T00:00:00Z': 47021,\n", " '2020-03-21T00:00:00Z': 53578}}" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "data.loc['Italy','timelines']['confirmed']" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "### Casos Confirmados desde 14 Dias antes da Confirmação de Mortes" ] }, { "cell_type": "code", "execution_count": 20, "metadata": { "hide_input": true }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%html\n", "" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "#### Italy" ] }, { "cell_type": "code", "execution_count": 21, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "Italy_confirmed = pd.Series(data.loc['Italy','timelines']['confirmed']['timeline'])\n", "Italy_deaths = pd.Series(data.loc['Italy','timelines']['deaths']['timeline'])\n", "\n", "day_first_death=(Italy_deaths == 0).sum()\n", "\n", "Italy_confirmed = Italy_confirmed.iloc[day_first_death-14:].reset_index(drop=True)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "#### Germany" ] }, { "cell_type": "code", "execution_count": 22, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "Germany_confirmed = pd.Series(data.loc['Germany','timelines']['confirmed']['timeline'])\n", "Germany_deaths = pd.Series(data.loc['Germany','timelines']['deaths']['timeline'])\n", "\n", "day_first_death=(Germany_deaths == 0).sum()\n", "\n", "Germany_confirmed = Germany_confirmed.iloc[day_first_death-14:].reset_index(drop=True)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "#### Spain" ] }, { "cell_type": "code", "execution_count": 23, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "Spain_confirmed = pd.Series(data.loc['Spain','timelines']['confirmed']['timeline'])\n", "Spain_deaths = pd.Series(data.loc['Spain','timelines']['deaths']['timeline'])\n", "\n", "day_first_death=(Spain_deaths == 0).sum()\n", "\n", "Spain_confirmed = Spain_confirmed.iloc[day_first_death-14:].reset_index(drop=True)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "#### Brazil" ] }, { "cell_type": "code", "execution_count": 24, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "Brazil_confirmed = pd.Series(data.loc['Brazil','timelines']['confirmed']['timeline'])\n", "Brazil_deaths = pd.Series(data.loc['Brazil','timelines']['deaths']['timeline'])\n", "\n", "day_first_death=(Brazil_deaths == 0).sum()\n", "\n", "Brazil_confirmed = Brazil_confirmed.iloc[day_first_death-14:].reset_index(drop=True)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "### Ajuste de Curvas e Previsões Casos Confirmados desde 14 dias antes da Confirmação de Mortes" ] }, { "cell_type": "code", "execution_count": 25, "metadata": { "hide_input": true }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%html\n", "" ] }, { "cell_type": "code", "execution_count": 26, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "code", "execution_count": 27, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "def exponential_func(x, a, c, d):\n", " return a*np.exp(c*x)+d" ] }, { "cell_type": "code", "execution_count": 28, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "from scipy.optimize import curve_fit" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "#### Italy" ] }, { "cell_type": "code", "execution_count": 29, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "days_to_predict=Italy_confirmed.size+5" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "y = np.array(Italy_confirmed.tolist())\n", "x = np.arange(y.size)\n", "\n", "popt, pcov = curve_fit(exponential_func, x, y)\n", "Italy_cases_prediction = exponential_func(np.arange(days_to_predict), *popt)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "#### Germany" ] }, { "cell_type": "code", "execution_count": 31, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "y = np.array(Germany_confirmed.tolist())\n", "x = np.arange(y.size)\n", "\n", "popt, pcov = curve_fit(exponential_func, x, y)\n", "Germany_cases_prediction = exponential_func(np.arange(days_to_predict), *popt)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "#### Spain" ] }, { "cell_type": "code", "execution_count": 32, "metadata": {}, "outputs": [], "source": [ "y = np.array(Spain_confirmed.tolist())\n", "x = np.arange(y.size)\n", "\n", "popt, pcov = curve_fit(exponential_func, x, y)\n", "Spain_cases_prediction = exponential_func(np.arange(days_to_predict), *popt)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "#### Brazil" ] }, { "cell_type": "code", "execution_count": 33, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "y = np.array(Brazil_confirmed.tolist()) \n", "x = np.arange(y.size)\n", "\n", "popt, pcov = curve_fit(exponential_func, x, y)\n", "Brazil_cases_prediction = exponential_func(np.arange(days_to_predict), *popt)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "### Mortes e Mortes/Casos (Ajuste de Curvas e Previsões)" ] }, { "cell_type": "code", "execution_count": 34, "metadata": { "hide_input": true }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%html\n", "" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "#### Italy\n", "\n" ] }, { "cell_type": "code", "execution_count": 35, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "Italy_deaths = np.trim_zeros(np.array(Italy_deaths.tolist()))\n", "Italy_death_rate=Italy_deaths/np.array(Italy_confirmed.tolist()[14:])" ] }, { "cell_type": "code", "execution_count": 36, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "days_to_predict=Italy_deaths.size+5" ] }, { "cell_type": "code", "execution_count": 37, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "y = Italy_deaths\n", "x = np.arange(y.size)\n", "\n", "popt, pcov = curve_fit(exponential_func, x, y)\n", "Italy_deaths_prediction = exponential_func(np.arange(days_to_predict), *popt)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "#### Spain" ] }, { "cell_type": "code", "execution_count": 38, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "Spain_deaths = np.trim_zeros(np.array(Spain_deaths.tolist()))\n", "Spain_death_rate=Spain_deaths/np.array(Spain_confirmed.tolist()[14:])" ] }, { "cell_type": "code", "execution_count": 39, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "y = Spain_deaths\n", "x = np.arange(y.size)\n", "\n", "popt, pcov = curve_fit(exponential_func, x, y)\n", "Spain_deaths_prediction = exponential_func(np.arange(days_to_predict), *popt)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "#### Germany" ] }, { "cell_type": "code", "execution_count": 40, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "Germany_deaths = np.trim_zeros(np.array(Germany_deaths.tolist()))\n", "Germany_death_rate=Germany_deaths/np.array(Germany_confirmed.tolist()[14:])" ] }, { "cell_type": "code", "execution_count": 41, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "y = Germany_deaths\n", "x = np.arange(y.size)\n", "\n", "popt, pcov = curve_fit(exponential_func, x, y)\n", "Germany_deaths_prediction = exponential_func(np.arange(days_to_predict), *popt)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "#### Brazil\n", "\n" ] }, { "cell_type": "code", "execution_count": 42, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "Brazil_deaths = np.trim_zeros(np.array(Brazil_deaths.tolist()))\n", "Brazil_death_rate=Brazil_deaths/np.array(Brazil_confirmed.tolist()[14:])" ] }, { "cell_type": "code", "execution_count": 43, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [], "source": [ "Brazil_deaths[4]=18\n", "y = Brazil_deaths\n", "x = np.arange(y.size)\n", "\n", "popt, pcov = curve_fit(exponential_func, x, y)\n", "Brazil_deaths_prediction = exponential_func(np.arange(days_to_predict), *popt)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Visualização de Dados" ] }, { "cell_type": "code", "execution_count": 44, "metadata": { "hide_input": true }, "outputs": [ { "data": { "text/html": [ "" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%%html\n", "" ] }, { "cell_type": "code", "execution_count": 45, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "text/html": [ " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import matplotlib.pyplot as plt\n", "import plotly.offline\n", "import plotly.tools as tls\n", "import plotly.plotly as py\n", "\n", "# Configurations\n", "plotly.offline.init_notebook_mode(connected=True)\n", "import warnings; warnings.simplefilter('ignore')" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "### Casos Confirmados e Mortes" ] }, { "cell_type": "code", "execution_count": 46, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "linkText": "Export to plot.ly", "plotlyServerURL": "https://plot.ly", "showLink": false }, "data": [ { "line": { "color": "rgba (255, 0, 0, 1)", "dash": "solid", "width": 1.5 }, "mode": "lines", "name": "Italy Cases", "type": "scatter", "uid": "7455fd7c-5a3d-497c-b140-a1b5fc74118a", "x": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 ], "xaxis": "x", "y": [ 20, 62, 155, 229, 322, 453, 655, 888, 1128, 1694, 2036, 2502, 3089, 3858, 4636, 5883, 7375, 9172, 10149, 12462, 12462, 17660, 21157, 24747, 27980, 31506, 35713, 41035, 47021, 53578 ], "yaxis": "y" }, { "marker": { "color": "#FF0000", "line": { "color": "#FF0000", "width": 1 }, "opacity": 1, "size": 3, "symbol": "x" }, "mode": "markers", "name": "Italy Cases Prediction", "type": "scatter", "uid": "6560bda9-d8d9-44fd-8d37-9b4437f0a19c", "x": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34 ], "xaxis": "x", "y": [ 33.60320696429642, 167.31391264241313, 321.68357408224404, 499.9041006451222, 705.660567246753, 943.2074108391572, 1217.4563996204752, 1534.0781939164635, 1899.6195987132119, 2321.638932277685, 2808.862309889944, 3371.364074173765, 4020.7751027927857, 4770.52330070105, 5636.111249618476, 6635.436755703575, 7789.162923404092, 9121.145407521288, 10658.925677800793, 12434.300495306898, 14483.979375672501, 16850.343633625824, 19582.322703596084, 22736.405856124366, 26377.810229391005, 30581.829327307492, 35435.38986713613, 41038.84916765566, 47508.07024255901, 54976.81750589564, 63599.52262568201, 73554.47771537573, 85047.52188899764, 98316.29740698809, 113635.16341734481 ], "yaxis": "y" }, { "line": { "color": "rgba (255, 0, 0, 1)", "dash": "5.550000000000001px,2.4000000000000004px", "width": 1.5 }, "mode": "lines", "name": "Italy Deaths", "type": "scatter", "uid": "e77cc14e-8265-4ecf-8808-b809f0cd4f06", "x": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 ], "xaxis": "x", "y": [ 1, 2, 3, 7, 10, 12, 17, 21, 29, 34, 52, 79, 107, 148, 197, 233, 366, 463, 631, 827, 827, 1266, 1441, 1809, 2158, 2503, 2978, 3405, 4032, 4825 ], "yaxis": "y" }, { "marker": { "color": "#FF0000", "line": { "color": "#FF0000", "width": 1 }, "opacity": 1, "size": 3, "symbol": "circle" }, "mode": "markers", "name": "Italy Deaths Prediction", "type": "scatter", "uid": "d81acbb5-642b-46e1-9f4c-3aaae32d2b25", "x": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34 ], "xaxis": "x", "y": [ -79.52043467313206, -72.56747688126197, -64.34075238451543, -54.6069099003132, -43.08984869998612, -29.462887003476737, -13.339495641029103, 5.737665858092214, 28.309721741520804, 55.01692903900528, 86.61683847191003, 124.00578240173218, 168.24429932392707, 220.58721607355847, 282.5192410254232, 355.7970778908167, 442.4992546700306, 545.0850811602797, 666.4644073505128, 810.0801614020289, 980.006008407143, 1181.0619000194797, 1418.9507925245443, 1700.4204113626797, 2033.4546505598687, 2427.5000361168486, 2893.733676997279, 3445.3803041525907, 4098.0873904048185, 4870.36899147391, 5784.130897713375, 6865.291992498651, 8144.519442117191, 9658.098570843202, 11448.962095229077 ], "yaxis": "y" }, { "line": { "color": "rgba (0, 0, 0, 1)", "dash": "solid", "width": 1.5 }, "mode": "lines", "name": "Spain Cases", "type": "scatter", "uid": "0008f5bb-30d4-4159-90fc-8452c8f921bd", "x": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 ], "xaxis": "x", "y": [ 165, 222, 259, 400, 500, 673, 1073, 1695, 2277, 2277, 5232, 6391, 7798, 9942, 11748, 13910, 17963, 20410, 25374 ], "yaxis": "y" }, { "marker": { "color": "#000000", "line": { "color": "#000000", "width": 1 }, "opacity": 1, "size": 3, "symbol": "x" }, "mode": "markers", "name": "Spain Cases Prediction", "type": "scatter", "uid": "b2116da6-ed4b-44b0-b7e0-e24e2a2f1038", "x": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34 ], "xaxis": "x", "y": [ 260.79863844174554, 410.279561957954, 593.7620233543715, 818.9801505118304, 1095.4273074459475, 1434.7562573023047, 1851.2703480515165, 2362.5264252771117, 2990.07488595449, 3760.368067867653, 4705.875264971502, 5866.451368676344, 7291.016825836758, 9039.619726806683, 11185.966944417283, 13820.531016105297, 17054.36373006675, 21023.777165203603, 25896.089499425634, 31876.677782841256, 39217.63496337864, 48228.3960746094, 59288.781499405544, 72865.00710731464, 89529.33612279696, 109984.20108721429, 135091.8127002485, 165910.5036086257, 203739.33910060904, 250172.87513021956, 307168.37182400585, 377128.2956450101, 463001.58783397515, 568407.9677814245, 697790.5109495281 ], "yaxis": "y" }, { "line": { "color": "rgba (0, 0, 0, 1)", "dash": "5.550000000000001px,2.4000000000000004px", "width": 1.5 }, "mode": "lines", "name": "Spain Deaths", "type": "scatter", "uid": "7c53c90e-42d9-4c87-b2b6-fa00569e607a", "x": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 ], "xaxis": "x", "y": [ 1, 2, 3, 5, 10, 17, 28, 35, 54, 55, 133, 195, 289, 342, 533, 623, 830, 1043, 1375 ], "yaxis": "y" }, { "marker": { "color": "#000000", "line": { "color": "#000000", "width": 1 }, "opacity": 1, "size": 3, "symbol": "circle" }, "mode": "markers", "name": "Spain Deaths Prediction", "type": "scatter", "uid": "6c28a9fd-0473-45fa-adff-3c7324b9363f", "x": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34 ], "xaxis": "x", "y": [ -20.1986612777649, -16.041806023925954, -10.676265392629755, -3.7505909324706757, 5.188856184624846, 16.72761897503066, 31.621498315581285, 50.84605868138798, 75.66052862625341, 107.69028155313094, 149.03329935025678, 202.39759237104892, 271.27857690834475, 360.1880285706868, 474.9496082432045, 623.0803178886664, 814.282871937536, 1061.0812351014622, 1379.6409549932023, 1790.828022186591, 2321.575614143791, 3006.648246148242, 3890.9188829509635, 5032.3081642942225, 6505.578266619155, 8407.229902816498, 10861.823218560341, 14030.136610461257, 18119.69787705208, 23398.37750386942, 30211.934456839313, 39006.66375155036, 50358.6292375854, 65011.3963754697, 83924.73654208562 ], "yaxis": "y" }, { "line": { "color": "rgba (0, 0, 255, 1)", "dash": "solid", "width": 1.5 }, "mode": "lines", "name": "Germany Cases", "type": "scatter", "uid": "c71a2742-ca01-49b1-b9b6-6ab81b7784ce", "x": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], "xaxis": "x", "y": [ 1176, 1457, 1908, 2078, 3675, 4585, 5795, 7272, 9257, 12327, 15320, 19848, 22213 ], "yaxis": "y" }, { "marker": { "color": "#0000FF", "line": { "color": "#0000FF", "width": 1 }, "opacity": 1, "size": 3, "symbol": "x" }, "mode": "markers", "name": "Germany Cases Prediction", "type": "scatter", "uid": "92163ac0-61a2-47d9-b437-4711dc86aa7d", "x": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34 ], "xaxis": "x", "y": [ 1360.2837842476215, 1761.574369311059, 2264.0448843351533, 2893.2064641630636, 3681.002527206821, 4667.430587733022, 5902.572985924257, 7449.139638738034, 9385.651910601035, 11810.429253532364, 14846.581024022704, 18648.256918233943, 23408.473368906518, 29368.91326115444, 36832.19651250338, 46177.24451178094, 57878.518491033545, 72530.10858967403, 90875.89664653061, 113847.32412717871, 142610.6827173515, 178626.32859237745, 223722.82675439876, 280189.7898496626, 350894.1250232336, 439425.59082745685, 550279.0543131594, 689082.7017524838, 862883.7895727574, 1080506.4434782704, 1352999.6717246475, 1694198.3388099722, 2121425.5810060366, 2656372.326354284, 3326198.573593811 ], "yaxis": "y" }, { "line": { "color": "rgba (0, 0, 255, 1)", "dash": "5.550000000000001px,2.4000000000000004px", "width": 1.5 }, "mode": "lines", "name": "Germany Deaths", "type": "scatter", "uid": "9d905255-6f70-4804-9798-65a7a3453973", "x": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], "xaxis": "x", "y": [ 2, 2, 3, 3, 7, 9, 11, 17, 24, 28, 44, 67, 84 ], "yaxis": "y" }, { "marker": { "color": "#0000FF", "line": { "color": "#0000FF", "width": 1 }, "opacity": 1, "size": 3, "symbol": "circle" }, "mode": "markers", "name": "Germany Deaths Prediction", "type": "scatter", "uid": "889c071c-2f21-4d10-b7f0-dae843ae8356", "x": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34 ], "xaxis": "x", "y": [ 1.387669874132175, 2.0440436992601834, 2.9550385314438716, 4.219427135153861, 5.974298276804143, 8.409920295826483, 11.790370562942835, 16.482167532750974, 22.994009762773985, 32.031930521404995, 44.5758480110959, 61.98581100926755, 86.1494593947748, 119.68668766801956, 166.23370169121318, 230.83726692393907, 320.50189371824683, 444.9492871275791, 617.6724030326384, 857.3983944788794, 1190.1190652110583, 1651.9089782055223, 2292.836766894334, 3182.393725056942, 4417.028259213044, 6130.603111215063, 8508.909154161443, 11809.809390475464, 16391.19722422942, 22749.800326608012, 31575.03732481464, 43823.766616532725, 60824.031798338285, 84419.05209543319, 117167.06966260319 ], "yaxis": "y" }, { "line": { "color": "rgba (0, 127, 0, 1)", "dash": "solid", "width": 1.5 }, "mode": "lines", "name": "Brazil Cases", "type": "scatter", "uid": "a78e4c02-d72c-4cca-bd6e-48b94baa1fa0", "x": [ 0, 1, 2, 3, 4 ], "xaxis": "x", "y": [ 321, 372, 621, 793, 1021 ], "yaxis": "y" }, { "marker": { "color": "#007F00", "line": { "color": "#007F00", "width": 1 }, "opacity": 1, "size": 3, "symbol": "x" }, "mode": "markers", "name": "Brazil Cases Prediction", "type": "scatter", "uid": "cc452cec-c9e7-4cac-aac7-4f1ad572c5ed", "x": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34 ], "xaxis": "x", "y": [ 315.8531954999931, 425.69660754127335, 573.3727092580201, 771.9119808718622, 1038.8329106277222, 1397.687771747124, 1880.1408018141624, 2528.7621566839234, 3400.7841687223267, 4573.151349929608, 6149.309736527047, 8268.334645671282, 11117.202249178556, 14947.287769782886, 20096.546049487828, 27019.33163442338, 36326.48960781155, 48839.2546615353, 65661.71429286044, 88278.2300535673, 118684.41299971793, 159563.2102086596, 214521.63969023174, 288409.06244493596, 387745.07500626595, 521294.7783751863, 700842.1832895399, 942229.9947055344, 1266757.5228421777, 1703060.0681143543, 2289635.611039727, 3078241.75438358, 4138462.653158385, 5563848.904186797, 7480172.159999504 ], "yaxis": "y" }, { "line": { "color": "rgba (0, 127, 0, 1)", "dash": "5.550000000000001px,2.4000000000000004px", "width": 1.5 }, "mode": "lines", "name": "Brazil Deaths", "type": "scatter", "uid": "08521106-a8c0-48ec-be20-5f9b5f1680bd", "x": [ 0, 1, 2, 3, 4 ], "xaxis": "x", "y": [ 1, 3, 6, 11, 18 ], "yaxis": "y" }, { "marker": { "color": "#007F00", "line": { "color": "#007F00", "width": 1 }, "opacity": 1, "size": 3, "symbol": "x" }, "mode": "markers", "name": "Brazil Deaths Prediction", "type": "scatter", "uid": "e5ce1483-ef85-43cc-80c0-1cd176773f8e", "x": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34 ], "xaxis": "x", "y": [ 0.9561413968095978, 3.0120747449660596, 6.130865284482359, 10.86197898430067, 18.038939590343816, 28.926178158014093, 45.44179948238933, 70.49551223376945, 108.50125905373724, 166.1548613631963, 253.61368370926587, 386.2861499517854, 587.5463867889843, 892.8522583005823, 1355.9923034693459, 2058.562157029388, 3124.3400017232407, 4741.093707400424, 7193.661620905657, 10914.13515328947, 16557.98429155267, 25119.537765382935, 38107.1630703025, 57809.00942056796, 87696.13200813124, 133034.01967021852, 201810.26441033217, 306141.80883090594, 464409.6991804553, 704497.4430628095, 1068703.503023617, 1621193.4051203034, 2459304.3688743156, 3730694.099073864, 5659354.999554958 ], "yaxis": "y" } ], "layout": { "autosize": false, "height": 576, "hovermode": "closest", "margin": { "b": 72, "l": 108, "pad": 0, "r": 86, "t": 69 }, "shapes": [ { "line": { "color": "LightSeaGreen", "dash": "dash", "width": 1 }, "type": "line", "x0": 11, "x1": 11, "xref": "x", "y0": 0, "y1": 10000000, "yref": "y" }, { "line": { "color": "LightSeaGreen", "dash": "dash", "width": 1 }, "type": "line", "x0": 18, "x1": 18, "xref": "x", "y0": 0, "y1": 10000000, "yref": "y" } ], "showlegend": true, "title": { "font": { "color": "#000000", "size": 12 }, "text": "Confirmed Cases and Curve Fit since 1st Death in each Country" }, "width": 864, "xaxis": { "anchor": "y", "domain": [ 0, 1 ], "mirror": "ticks", "nticks": 10, "range": [ -1.7000000000000002, 35.7 ], "showgrid": true, "showline": true, "side": "bottom", "tickfont": { "size": 10 }, "ticks": "inside", "title": { "font": { "color": "#000000", "size": 10 }, "text": "Number of Days since 1st Death in each Country" }, "type": "linear", "zeroline": false }, "yaxis": { "anchor": "x", "domain": [ 0, 1 ], "mirror": "ticks", "nticks": 12, "range": [ -0.3641473519069369, 7.218581067080097 ], "showgrid": true, "showline": true, "side": "left", "tickfont": { "size": 10 }, "ticks": "inside", "title": { "font": { "color": "#000000", "size": 10 }, "text": "Number of Cases" }, "type": "log", "zeroline": false } } }, "text/html": [ "
\n", " \n", " \n", "
\n", " \n", "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig=plt.figure(figsize=(12,8))\n", "plt.yscale('log')\n", "plt.xlabel('Number of Days since 1st Death in each Country')\n", "plt.ylabel('Number of Cases')\n", "plt.title('Confirmed Cases and Curve Fit since 1st Death in each Country')\n", "plt.grid()\n", "## Italy\n", "# Italy Case\n", "plt.plot(Italy_confirmed.tolist()[14:], 'r', label='Italy Cases')\n", "plt.plot(Italy_cases_prediction[14:], 'rx',label = 'Italy Cases Prediction', markersize=3)\n", "# Italy Deaths\n", "plt.plot(Italy_deaths, 'r', label='Italy Deaths',linestyle='dashed')\n", "plt.plot(Italy_deaths_prediction, 'r.',label = 'Italy Deaths Prediction', markersize=3)\n", "\n", "## Spain\n", "# Spain Cases\n", "plt.plot(Spain_confirmed.tolist()[14:], 'k', label='Spain Cases')\n", "plt.plot(Spain_cases_prediction[14:], 'kx',label = 'Spain Cases Prediction', markersize=3)\n", "#Spain Deaths\n", "plt.plot(Spain_deaths, 'k', label='Spain Deaths',linestyle='dashed')\n", "plt.plot(Spain_deaths_prediction, 'k.',label = 'Spain Deaths Prediction', markersize=3)\n", "\n", "## Germany\n", "# Germany Cases\n", "plt.plot(Germany_confirmed.tolist()[14:], 'b', label='Germany Cases')\n", "plt.plot(Germany_cases_prediction[14:], 'bx',label = 'Germany Cases Prediction', markersize=3)\n", "# Germany Deaths\n", "plt.plot(Germany_deaths, 'b', label='Germany Deaths',linestyle='dashed')\n", "plt.plot(Germany_deaths_prediction, 'b.',label = 'Germany Deaths Prediction', markersize=3)\n", "\n", "## Brazil\n", "# Brazil Cases\n", "plt.plot(Brazil_confirmed.tolist()[14:], 'g', label='Brazil Cases')\n", "plt.plot(Brazil_cases_prediction[14:], 'gx',label = 'Brazil Cases Prediction', markersize=3)\n", "# Brazil Deaths\n", "plt.plot(Brazil_deaths,label = 'Brazil Deaths', linestyle='dashed', color='g')\n", "plt.plot(Brazil_deaths_prediction, 'gx',label = 'Brazil Deaths Prediction', markersize=3)\n", "\n", "\n", "# Transfomr to Plotlly\n", "plotly_fig = tls.mpl_to_plotly(fig)\n", "shapes = list()\n", "for i in (11, 18):\n", " shapes.append({'type': 'line',\n", " 'xref': 'x',\n", " 'yref': 'y',\n", " 'x0': i,\n", " 'y0': 0,\n", " 'x1': i,\n", " 'y1': 10000000,\n", " 'line' : dict(color=\"LightSeaGreen\", \n", " width=1,\n", " dash=\"dash\",)},\n", " )\n", " \n", "plotly_fig.layout.update(showlegend=True, shapes=shapes)\n", "plotly.offline.iplot(plotly_fig)" ] }, { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "-" } }, "source": [ "### Mortes / Casos Confirmados" ] }, { "cell_type": "code", "execution_count": 47, "metadata": { "slideshow": { "slide_type": "-" } }, "outputs": [ { "data": { "application/vnd.plotly.v1+json": { "config": { "linkText": "Export to plot.ly", "plotlyServerURL": "https://plot.ly", "showLink": false }, "data": [ { "line": { "color": "rgba (255, 0, 0, 1)", "dash": "solid", "width": 1.5 }, "mode": "lines", "name": "Italy Deaths/Cases", "type": "scatter", "uid": "49f238b8-28c5-4df4-b916-21746abc3172", "x": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29 ], "xaxis": "x", "y": [ 0.05, 0.03225806451612903, 0.01935483870967742, 0.03056768558951965, 0.031055900621118012, 0.026490066225165563, 0.025954198473282442, 0.02364864864864865, 0.025709219858156027, 0.020070838252656435, 0.025540275049115914, 0.03157474020783373, 0.03463904176108773, 0.0383618455158113, 0.042493528904227786, 0.039605643379228284, 0.0496271186440678, 0.050479720889664195, 0.062173613163858506, 0.06636173968865351, 0.06636173968865351, 0.07168742921857305, 0.06810984544122513, 0.0730997696690508, 0.0771265189421015, 0.07944518504411859, 0.08338700193206955, 0.08297794565614719, 0.08574892069500861, 0.0900556198439658 ], "yaxis": "y" }, { "line": { "color": "rgba (0, 0, 0, 1)", "dash": "solid", "width": 1.5 }, "mode": "lines", "name": "Spain Deaths/Cases", "type": "scatter", "uid": "76703bc3-22c4-4f2f-989d-e613e1e8b780", "x": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18 ], "xaxis": "x", "y": [ 0.006060606060606061, 0.009009009009009009, 0.011583011583011582, 0.0125, 0.02, 0.02526002971768202, 0.0260950605778192, 0.02064896755162242, 0.023715415019762844, 0.024154589371980676, 0.025420489296636085, 0.030511657017681115, 0.037060784816619646, 0.0343995171997586, 0.04536942458290773, 0.04478792235801582, 0.046206090296721035, 0.05110240078392945, 0.05418932765823284 ], "yaxis": "y" }, { "line": { "color": "rgba (0, 0, 255, 1)", "dash": "solid", "width": 1.5 }, "mode": "lines", "name": "Germany Deaths/Cases", "type": "scatter", "uid": "d8b79877-b13f-4e94-b9d6-9a71c3e0ccb6", "x": [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ], "xaxis": "x", "y": [ 0.0017006802721088435, 0.0013726835964310226, 0.0015723270440251573, 0.0014436958614051972, 0.0019047619047619048, 0.0019629225736095966, 0.0018981880931837791, 0.0023377337733773377, 0.0025926326023549746, 0.002271436683702442, 0.0028720626631853785, 0.0033756549778315194, 0.0037815693512807816 ], "yaxis": "y" }, { "line": { "color": "rgba (0, 127, 0, 1)", "dash": "solid", "width": 1.5 }, "mode": "lines", "name": "Brazil Deaths/Cases", "type": "scatter", "uid": "cb39252e-6fc5-401b-b57a-6beb3a1507df", "x": [ 0, 1, 2, 3, 4 ], "xaxis": "x", "y": [ 0.003115264797507788, 0.008064516129032258, 0.00966183574879227, 0.013871374527112233, 0.014691478942213516 ], "yaxis": "y" } ], "layout": { "autosize": false, "height": 576, "hovermode": "closest", "margin": { "b": 72, "l": 108, "pad": 0, "r": 86, "t": 69 }, "shapes": [ { "line": { "color": "LightSeaGreen", "dash": "dash", "width": 1 }, "type": "line", "x0": 11, "x1": 11, "xref": "x", "y0": 0, "y1": 10000000, "yref": "y" }, { "line": { "color": "LightSeaGreen", "dash": "dash", "width": 1 }, "type": "line", "x0": 18, "x1": 18, "xref": "x", "y0": 0, "y1": 10000000, "yref": "y" } ], "showlegend": true, "title": { "font": { "color": "#000000", "size": 12 }, "text": "Deaths / Cases since 1st Death in each Country" }, "width": 864, "xaxis": { "anchor": "y", "domain": [ 0, 1 ], "mirror": "ticks", "nticks": 9, "range": [ -1.4500000000000002, 30.45 ], "showgrid": true, "showline": true, "side": "bottom", "tickfont": { "size": 10 }, "ticks": "inside", "title": { "font": { "color": "#000000", "size": 10 }, "text": "Number of Days since 1st Death in each Country" }, "type": "linear", "zeroline": false }, "yaxis": { "anchor": "x", "domain": [ 0, 1 ], "mirror": "ticks", "nticks": 6, "range": [ -2.9532765749001633, -0.9546421614287719 ], "showgrid": true, "showline": true, "side": "left", "tickfont": { "size": 10 }, "ticks": "inside", "title": { "font": { "color": "#000000", "size": 10 }, "text": "Number of Deaths / Cases" }, "type": "log", "zeroline": false } } }, "text/html": [ "
\n", " \n", " \n", "
\n", " \n", "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "fig=plt.figure(figsize=(12,8))\n", "plt.yscale('log')\n", "plt.xlabel('Number of Days since 1st Death in each Country')\n", "plt.ylabel('Number of Deaths / Cases')\n", "plt.title('Deaths / Cases since 1st Death in each Country')\n", "plt.grid()\n", "\n", "## Italy\n", "plt.plot(Italy_death_rate, 'r', label='Italy Deaths/Cases')\n", "\n", "## Spain\n", "plt.plot(Spain_death_rate, 'k', label='Spain Deaths/Cases')\n", "\n", "## Germany\n", "plt.plot(Germany_death_rate, 'b', label='Germany Deaths/Cases')\n", "\n", "## Brazil\n", "plt.plot(Brazil_death_rate, 'g', label='Brazil Deaths/Cases')\n", "\n", "# Transfomr to Plotlly\n", "plotly_fig = tls.mpl_to_plotly(fig)\n", "shapes = list()\n", "for i in (11, 18):\n", " shapes.append({'type': 'line',\n", " 'xref': 'x',\n", " 'yref': 'y',\n", " 'x0': i,\n", " 'y0': 0,\n", " 'x1': i,\n", " 'y1': 10000000,\n", " 'line' : dict(color=\"LightSeaGreen\", \n", " width=1,\n", " dash=\"dash\",)},\n", " )\n", " \n", "plotly_fig.layout.update(showlegend=True, shapes=shapes)\n", "plotly.offline.iplot(plotly_fig)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "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.6.6" }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 2 }