mysql 時間推移_隨著時間的推移可視化COVID-19新案例

mysql 時間推移

This heat map shows the progression of the COVID-19 pandemic in the United States over time. The map is read from left to right, and color coded to show the relative numbers of new cases by state, adjusted for population.

該熱圖顯示了美國COVID-19大流行隨著時間的進展。 從左到右讀取地圖,并用顏色編碼顯示按州調整的新病例的相對數量,并根據人口進行調整。

This visualization was inspired by a similar heat map that I saw on a discussion forum thread. I could never locate the source, as it was only a pasted image with no link. The original version was also crafted to make a political point, separating states by predominate party affiliation, which I was not as interested in. I was fascinated by how it concisely showed the progression of the pandemic, so I decided to create a similar visualization myself that I could update regularly.

這種可視化的靈感來自我在討論論壇主題中看到的類似熱圖。 我永遠找不到源,因為它只是一個粘貼的圖像,沒有鏈接。 最初的版本還經過精心設計以提出政治觀點,以政黨之間的支配關系分隔國家,對此我并不感興趣。我可以定期更新。

Source code is hosted on my Github repo. If you are just interested in seeing updated versions of this heat map, I publish them weekly on my Twitter feed. It’s important to note that you should be careful comparing graphs from one week to another to each other, as the color map may change as new data is included. Comparisons are only valid within a given heatmap.

源代碼托管在我的Github存儲庫中 。 如果您只想查看此熱圖的更新版本,我每周都會在Twitter feed上發布它們。 重要的是要注意,您應該謹慎比較一周之間的圖表,因為隨著添加新數據,顏色圖可能會發生變化。 比較僅在給定的熱圖中有效。

The script relies on pandas, numpy, matplotlib, and seaborn.

該腳本依賴于pandas,numpy,matplotlib和seaborn。

The data comes from the New York Times COVID-19 Github repo. A simple launcher script clones the latest copy of the repository and copies the required file, and then launches the Python script to create the heat map. Only one file is really needed, so it could certainly be tightened up, but this works.

數據來自《紐約時報》 COVID-19 Github存儲庫 。 一個簡單的啟動器腳本將克隆存儲庫的最新副本并復制所需的文件,然后啟動Python腳本以創建熱圖。 確實只需要一個文件,因此可以將其收緊,但這是可行的。

echo "Clearing old data..."
rm -rf covid-19-data/
rm us-states.csv
echo "Getting new data..."
git clone https://github.com/nytimes/covid-19-data
echo "Done."cp covid-19-data/us-states.csv .
echo "Starting..."python3 heatmap-newcases.py
echo "Done."

The script first loads a CSV file containing the state populations into a dictionary, which is used to scale daily new case results. The new cases are computed for each day from the running total in the NY Times data, and then scaled to new cases per 100,000 people in the population.

該腳本首先將包含州人口的CSV文件加載到字典中,該字典用于擴展每日新個案結果。 根據《紐約時報》數據中的運行總計每天計算新病例,然后將其擴展為人口中每100,000人的新病例 。

We could display the heat map at that point, but if we do, states with very high numbers of cases per 100,000 people will swamp the detail of the states with lower numbers of cases. Applying a log(x+1) transform improves contrast and readability significantly.

我們可以在那時顯示熱圖,但是如果這樣做,每10萬人中案件數量非常多的州將淹沒案件數量較少的州的詳細信息。 應用log(x + 1)變換可顯著提高對比度和可讀性。

Finally, Seaborn and Matplotlib are used to generate the heatmap and save it to an image file.

最后,使用Seaborn和Matplotlib生成熱圖并將其保存到圖像文件中。

That’s it! Feel free to use this as a framework for your own visualization. You can customize it to zero in on areas of interest.

而已! 隨意使用它作為您自己的可視化框架。 您可以在感興趣的區域將其自定義為零。

Full source code is below. Thanks for reading, and I hope you found it useful.

完整的源代碼如下。 感謝您的閱讀,希望您覺得它有用。

import numpy as np
import seaborn as sns
import matplotlib.pylab as plt
import pandas as pd
import csv
import datetimereader = csv.reader(open('StatePopulations.csv'))statePopulations = {}
for row in reader:key = row[0]if key in statePopulations:passstatePopulations[key] = row[1:]filename = "us-states.csv"
fullTable = pd.read_csv(filename)
fullTable = fullTable.drop(['fips'], axis=1)
fullTable = fullTable.drop(['deaths'], axis=1)# generate a list of the dates in the table
dates = fullTable['date'].unique().tolist()
states = fullTable['state'].unique().tolist()result = pd.DataFrame()
result['date'] = fullTable['date']states.remove('Northern Mariana Islands')
states.remove('Puerto Rico')
states.remove('Virgin Islands')
states.remove('Guam')states.sort()for state in states:# create new dataframe with only the current state's datepopulation = int(statePopulations[state][0])print(state + ": " + str(population))stateData = fullTable[fullTable.state.eq(state)]newColumnName = statestateData[newColumnName] = stateData.cases.diff()stateData[newColumnName] = stateData[newColumnName].replace(np.nan, 0)stateData = stateData.drop(['state'], axis=1)stateData = stateData.drop(['cases'], axis=1)stateData[newColumnName] = stateData[newColumnName].div(population)stateData[newColumnName] = stateData[newColumnName].mul(100000.0)result = pd.merge(result, stateData, how='left', on='date')result = result.drop_duplicates()
result = result.fillna(0)for state in states:result[state] = result[state].add(1.0)result[state] = np.log10(result[state])#result[state] = np.sqrt(result[state])result['date'] = pd.to_datetime(result['date'])
result = result[result['date'] >= '2020-02-15']
result['date'] = result['date'].dt.strftime('%Y-%m-%d')result.set_index('date', inplace=True)
result.to_csv("result.csv")
result = result.transpose()plt.figure(figsize=(16, 10))
g = sns.heatmap(result, cmap="coolwarm", linewidth=0.05, linecolor='lightgrey')
plt.xlabel('')
plt.ylabel('')plt.title("Daily New Covid-19 Cases Per 100k Of Population", fontsize=20)updateText = "Updated " + str(datetime.date.today()) + \". Scaled with Log(x+1) for improved contrast due to wide range of values. Data source: NY Times Github. Visualization by @JRBowling"plt.suptitle(updateText, fontsize=8)plt.yticks(np.arange(.5, 51.5, 1.0), states)plt.yticks(fontsize=8)
plt.xticks(fontsize=8)
g.set_xticklabels(g.get_xticklabels(), rotation=90)
g.set_yticklabels(g.get_yticklabels(), rotation=0)
plt.savefig("covidNewCasesper100K.png")

翻譯自: https://towardsdatascience.com/visualization-of-covid-19-new-cases-over-time-in-python-8c6ac4620c88

mysql 時間推移

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/392250.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/392250.shtml
英文地址,請注明出處:http://en.pswp.cn/news/392250.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

leetcode 959. 由斜杠劃分區域(并查集)

在由 1 x 1 方格組成的 N x N 網格 grid 中,每個 1 x 1 方塊由 /、\ 或空格構成。這些字符會將方塊劃分為一些共邊的區域。 (請注意,反斜杠字符是轉義的,因此 \ 用 “\” 表示。)。 返回區域的數目。 示例 1&#x…

rcu寬限期_如何處理寬限期錯誤:靜默失敗不是一種選擇

rcu寬限期by Rina Artstain通過麗娜阿斯特斯坦 I’ve never really had much of an opinion about error handling. This may come as a shock to people who know me as quite opinionated (in a good way!), but yeah. If I was coming into an existing code base I just d…

描述符、迭代器、生成器

描述符:將某種特殊類型的類的實例指派給另一個類的屬性。 此處特殊類型的要求,至少實現”__set__(self , instance , owner)“、”__get__(self , instance , value)“、”__delete__(self , instance )“三個方法中的一個。 >>> class MyDecri…

php模擬表單提交登錄,PHP模擬表單的post請求實現登錄

stuid > $stuid,pwd > $pwd);$ch curl_init (); //初始化curlcurl_setopt ( $ch, CURLOPT_URL, $uri );curl_setopt ( $ch, CURLOPT_POST, 1 ); //使用post請求curl_setopt ( $ch, CURLOPT_HEADER, 0 );curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );curl_setopt ( $…

去除list集合中重復項的幾種方法

因為用到list&#xff0c;要去除重復數據&#xff0c;嘗試了幾種方法。記錄于此。。。 測試數據&#xff1a; List<string> li1 new List<string> { "8", "8", "9", "9" ,"0","9"};List<string&g…

Crystal Reports第一張報表

新建一個網站項目&#xff0c;1. 設置數據庫 從服務器資源管理器中&#xff0c;數據連接中添加新連接&#xff0c;用Microsoft Access數據庫文件作為數據提供程序&#xff0c;連接上Crystal Reports的用例的數據庫Xtreme2. 創建新Crystal Reports報表 在工程項目中添加一個…

leetcode 1128. 等價多米諾骨牌對的數量

給你一個由一些多米諾骨牌組成的列表 dominoes。 如果其中某一張多米諾骨牌可以通過旋轉 0 度或 180 度得到另一張多米諾骨牌&#xff0c;我們就認為這兩張牌是等價的。 形式上&#xff0c;dominoes[i] [a, b] 和 dominoes[j] [c, d] 等價的前提是 ac 且 bd&#xff0c;或是…

海量數據尋找最頻繁的數據_尋找數據科學家的“原因”

海量數據尋找最頻繁的數據Start with “Why” - Why do we do the work we do?從“為什么”開始-我們為什么要做我們所做的工作&#xff1f; The question of “Why” is always a big question. Plus, it always makes you look smart in a meeting!“ 為什么 ”的問題始終是…

C語言中局部變量和全局變量 變量的存儲類別

C語言中局部變量和全局變量 變量的存儲類別(static,extern,auto,register) 局部變量和全局變量在討論函數的形參變量時曾經提到&#xff0c;形參變量只在被調用期間才分配內存單元&#xff0c;調用結束立即釋放。這一點表明形參變量只有在函數內才是有效的&#xff0c;離開該函…

營銷 客戶旅程模板_我如何在國外找到開發人員的工作:我從營銷到技術的旅程...

營銷 客戶旅程模板by Dimitri Ivashchuk由Dimitri Ivashchuk 我如何在國外找到開發人員的工作&#xff1a;我從營銷到技術的旅程 (How I got a developer job abroad: my journey from marketing to tech) In this post, I’ll go into the details of how I, a Ukrainian mar…

keepalive的作用

keepalive的作用是實現高可用,通過VIP虛擬IP的漂移實現高可用.在相同集群內發送組播包,master主通過VRRP協議發送組播包,告訴從主的狀態. 一旦主掛了從就選舉新的主,實現高可用 LVS專屬技能,通過配置文件控制lvs集群節點.對后端真實服務器進行健康檢查. 轉載于:https://www.cnb…

scrapy.Spider的屬性和方法

scrapy.Spider的屬性和方法 屬性: name:spider的名稱,要求唯一 allowed_domains:允許的域名,限制爬蟲的范圍 start_urls:初始urls custom_settings:個性化設置,會覆蓋全局的設置 crawler:抓取器,spider將綁定到它上面 custom_settings:配置實例,包含工程中所有的配置變量 logge…

php時間操作函數總結,基于php常用函數總結(數組,字符串,時間,文件操作)

數組:【重點1】implode(分隔,arr) 把數組值數據按指定字符連接起來例如&#xff1a;$arrarray(1,2,3,4);$strimplode(-,$arr);explode([分隔],arr)按指定規則對一個字符串進行分割&#xff0c;返回值為數組 別名joinarray_merge()合并一個或多個數組array_combine(array keys, …

kaggle比賽數據_表格數據二進制分類:來自5個Kaggle比賽的所有技巧和竅門

kaggle比賽數據This article was originally written by Shahul ES and posted on the Neptune blog.本文最初由 Shahul ES 撰寫&#xff0c; 并發布在 Neptune博客上。 In this article, I will discuss some great tips and tricks to improve the performance of your stru…

leetcode 1579. 保證圖可完全遍歷(并查集)

Alice 和 Bob 共有一個無向圖&#xff0c;其中包含 n 個節點和 3 種類型的邊&#xff1a; 類型 1&#xff1a;只能由 Alice 遍歷。 類型 2&#xff1a;只能由 Bob 遍歷。 類型 3&#xff1a;Alice 和 Bob 都可以遍歷。 給你一個數組 edges &#xff0c;其中 edges[i] [typei,…

別把“運氣”當“實力”

成功是兩分靠努力&#xff0c;八分靠天命–何英圻何英圻先生&#xff0c;大家口中的Steven&#xff0c;是臺灣網路創業圈的傳奇人物。他先后創辦力傳(Ubid)與興奇(Monday)兩家公司&#xff0c;最后都以高價出售給北美網路巨人—Ubid在2002年以美金950萬賣給eBay&#xff0c;而M…

品牌推廣前期要進行哪些針對性的步驟?

企業在品牌推廣前需要制訂一系列有針對性和連續性的步驟&#xff0c;這些步驟定睛于長期策略&#xff0c;而且要適應目標客戶的使用方式和習慣。在企業內部導入品牌VI是前提&#xff0c;外部的宣傳則是強調品牌所宣揚的內涵和精神實質&#xff0c;總體來說&#xff0c;這只是一…

php的set 容器,關于STL中set容器的一些總結

1.關于setC STL 之所以得到廣泛的贊譽&#xff0c;也被很多人使用&#xff0c;不只是提供了像vector, string, list等方便的容器&#xff0c;更重要的是STL封裝了許多復雜的數據結構算法和大量常用數據結構操作。vector封裝數組&#xff0c;list封裝了鏈表&#xff0c;map和set…

強化學習應用于組合優化問題_如何將強化學習應用于現實生活中的計劃問題

強化學習應用于組合優化問題by Sterling Osborne, PhD Researcher作者&#xff1a;斯特林奧斯本(Sterling Osborne)&#xff0c;博士研究員 如何將強化學習應用于現實生活中的計劃問題 (How to apply Reinforcement Learning to real life planning problems) Recently, I hav…

導入導出報錯

導入導出報錯&#xff1a;另&#xff1a;右鍵--共享&#xff1a;停止共享&#xff1b;可能無效。此時&#xff0c;可以通過修改文件夾的權限&#xff0c;來達到停止共享的目的&#xff1b;轉載于:https://www.cnblogs.com/chenjx/p/7107336.html