Browse Source

tring to add some maps

master
杨浩然 4 years ago
parent
commit
f589fc7ce5
4 changed files with 350 additions and 15 deletions
  1. BIN
      COVID-19/Project/.vs/Project/v16/.suo
  2. +47
    -15
      COVID-19/Project/Project/Project.py
  3. +4
    -0
      COVID-19/Project/Project/Project.pyproj
  4. +299
    -0
      COVID-19/Project/Project/province.html

BIN
COVID-19/Project/.vs/Project/v16/.suo View File


+ 47
- 15
COVID-19/Project/Project/Project.py View File

@ -5,6 +5,8 @@ import numpy as np
import datetime
import math
from scipy import interpolate
from pyecharts.charts import Map
from pyecharts import options
plt.rcParams['axes.unicode_minus'] = False
@ -37,7 +39,6 @@ dfChinaSept = China[China['Date'].dt.month == 9]
dfChinaOct = China[China['Date'].dt.month == 10]
dfChinaNov = China[China['Date'].dt.month == 11]
dfChinaDec = China[China['Date'].dt.month == 12]
dfUSJan = US[US['Date'].dt.month == 1]
dfUSFeb = US[US['Date'].dt.month == 2]
dfUSMar = US[US['Date'].dt.month == 3]
@ -58,7 +59,6 @@ recoveredChina = [dfChinaJan['Recovered'].sum(),dfChinaFeb['Recovered'].sum(),df
dfChinaMay['Recovered'].sum(),dfChinaJun['Recovered'].sum(),dfChinaJul['Recovered'].sum(),dfChinaAug['Recovered'].sum(),
dfChinaSept['Recovered'].sum(),dfChinaOct['Recovered'].sum(),dfChinaNov['Recovered'].sum(),dfChinaDec['Recovered'].sum()]
recoverPossChina = []
confirmedUS = [dfUSJan['Confirmed'].sum(),dfUSFeb['Confirmed'].sum(),dfUSMar['Confirmed'].sum(),dfUSApr['Confirmed'].sum(),
dfUSMay['Confirmed'].sum(),dfUSJun['Confirmed'].sum(),dfUSJul['Confirmed'].sum(),dfUSAug['Confirmed'].sum(),
dfUSSept['Confirmed'].sum(),dfUSOct['Confirmed'].sum(),dfUSNov['Confirmed'].sum(),dfUSDec['Confirmed'].sum()]
@ -102,28 +102,41 @@ datasUS = data3 + data4 + data5
labsUS = [d.get_label() for d in datasUS]
ax3.legend(datasUS, labsUS, loc="upper left")
dataNew = pd.melt(China[['Date','Province/State','Confirmed','Recovered','Deaths']],
#中国各省数据
dataChina = pd.melt(China[['Date','Province/State','Confirmed','Recovered','Deaths']],
id_vars=['Date','Province/State'],value_vars=['Confirmed','Recovered','Deaths'],
var_name='group_var',value_name='Cases')
dataNew['Date'] = pd.to_datetime(dataNew['Date'])
dfNew = China[['Province/State','Confirmed','Recovered','Deaths']].groupby(['Province/State']).sum().reset_index()
dataNew = pd.melt(dfNew,id_vars=['Province/State'],
dataChina['Date'] = pd.to_datetime(dataChina['Date'])
dfChina = China[['Province/State','Confirmed','Recovered','Deaths']].groupby(['Province/State']).sum().reset_index()
dataChina = pd.melt(dfChina,id_vars=['Province/State'],
value_vars=['Confirmed','Deaths','Recovered'],
var_name='group_var',value_name='Cases')
dataChina = dataChina.sort_values(by=['Province/State','group_var']).reset_index(drop=True)
dataChina = dataChina.pivot_table(index=['Province/State'], columns='group_var')
dataChina.columns = dataChina.columns.droplevel().rename(None)
#各国数据
dataWorld = pd.melt(dataset[['Date','Country/Region','Confirmed','Recovered','Deaths']],
id_vars=['Date','Country/Region'],value_vars=['Confirmed','Recovered','Deaths'],
var_name='group_var',value_name='Cases')
dataWorld['Date'] = pd.to_datetime(dataWorld['Date'])
dfWorld = dataset[['Country/Region','Confirmed','Recovered','Deaths']].groupby(['Country/Region']).sum().reset_index()
dataWorld = pd.melt(dfWorld,id_vars=['Country/Region'],
value_vars=['Confirmed','Deaths','Recovered'],
var_name='group_var',value_name='Cases')
dataNew = dataNew.sort_values(by=['Province/State','group_var']).reset_index(drop=True)
dataNew = dataNew.pivot_table(index=['Province/State'], columns='group_var')
dataNew.columns = dataNew.columns.droplevel().rename(None)
dataWorld = dataWorld.sort_values(by=['Country/Region','group_var']).reset_index(drop=True)
dataWorld = dataWorld.pivot_table(index=['Country/Region'], columns='group_var')
dataWorld.columns = dataWorld.columns.droplevel().rename(None)
#中国各省份
dataNew.sort_values('Confirmed', inplace=True)
dataChina.sort_values('Confirmed', inplace=True)
xData = []
yConfirmed = []
yRecovered = []
for i in range(12):
xData.append(dataNew.index[i])
yConfirmed.append(dataNew['Confirmed'][i])
yRecovered.append(dataNew['Recovered'][i])
xData.append(dataChina.index[i])
yConfirmed.append(dataChina['Confirmed'][i])
yRecovered.append(dataChina['Recovered'][i])
ax5 = fig.add_subplot(212)
ax5.set_title("Total Recovered/Confirmed of China(the bottom ten)",verticalalignment="bottom",fontsize="13")
@ -134,4 +147,23 @@ ax5.bar(r1, yConfirmed, color='#FF0088', width=barWidth, edgecolor='white', labe
ax5.bar(r2, yRecovered, color='#00BBFF', width=barWidth, edgecolor='white', label='Recovered')
plt.xticks([r + barWidth for r in range(len(yConfirmed))], xData)
ax5.legend()
plt.show()
plt.show()
ChinaConfirmed=[]
worldConfirmed=[]
for i in range(33):
ChinaConfirmed.append((dataChina.index[i],dataChina['Confirmed'][i]))
map_China = Map()
map_China.set_global_opts(title_opts=options.TitleOpts(title="疫情图-确诊人数"),
visualmap_opts=options.VisualMapOpts(is_piecewise=True,
pieces=[
{"min": 1000, "label": '>1000人',"color": "#6F171F"},
{"min": 500, "max": 1000,"label": '500-1000人', "color": "#C92C34"},
{"min": 100, "max": 499,"label": '100-499人', "color": "#E35B52"},
{"min": 10, "max": 99,"label": '10-99人', "color": "#F39E86"},
{"min": 1, "max": 9, "label": '1-9人', "color": "#FDEBD0"}]))
map_China.add("确诊", ChinaConfirmed, maptype='china')
map_China.render("province.html")

+ 4
- 0
COVID-19/Project/Project/Project.pyproj View File

@ -11,6 +11,7 @@
<OutputPath>.</OutputPath>
<Name>Project</Name>
<RootNamespace>Project</RootNamespace>
<InterpreterId>CondaEnv|CondaEnv|env</InterpreterId>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
@ -23,6 +24,9 @@
<ItemGroup>
<Compile Include="Project.py" />
</ItemGroup>
<ItemGroup>
<InterpreterReference Include="CondaEnv|CondaEnv|env" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
<!-- Uncomment the CoreCompile target to enable the Build command in
Visual Studio and specify your pre- and post-build commands in

+ 299
- 0
COVID-19/Project/Project/province.html View File

@ -0,0 +1,299 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Awesome-pyecharts</title>
<script type="text/javascript" src="https://assets.pyecharts.org/assets/echarts.min.js"></script>
<script type="text/javascript" src="https://assets.pyecharts.org/assets/maps/china.js"></script>
</head>
<body>
<div id="c11071484495441fb56547337c4c9980" class="chart-container" style="width:900px; height:500px;"></div>
<script>
var chart_c11071484495441fb56547337c4c9980 = echarts.init(
document.getElementById('c11071484495441fb56547337c4c9980'), 'white', {renderer: 'canvas'});
var option_c11071484495441fb56547337c4c9980 = {
"animation": true,
"animationThreshold": 2000,
"animationDuration": 1000,
"animationEasing": "cubicOut",
"animationDelay": 0,
"animationDurationUpdate": 300,
"animationEasingUpdate": "cubicOut",
"animationDelayUpdate": 0,
"color": [
"#c23531",
"#2f4554",
"#61a0a8",
"#d48265",
"#749f83",
"#ca8622",
"#bda29a",
"#6e7074",
"#546570",
"#c4ccd3",
"#f05b72",
"#ef5b9c",
"#f47920",
"#905a3d",
"#fab27b",
"#2a5caa",
"#444693",
"#726930",
"#b2d235",
"#6d8346",
"#ac6767",
"#1d953f",
"#6950a1",
"#918597"
],
"series": [
{
"type": "map",
"name": "\u786e\u8bca",
"label": {
"show": true,
"position": "top",
"margin": 8
},
"mapType": "china",
"data": [
{
"name": "Tibet",
"value": 315.0
},
{
"name": "Qinghai",
"value": 5645.0
},
{
"name": "Macau",
"value": 11994.0
},
{
"name": "Ningxia",
"value": 23057.0
},
{
"name": "Jilin",
"value": 42570.0
},
{
"name": "Guizhou",
"value": 45186.0
},
{
"name": "Gansu",
"value": 47108.0
},
{
"name": "Hainan",
"value": 52669.0
},
{
"name": "Shanxi",
"value": 58587.0
},
{
"name": "Yunnan",
"value": 60036.0
},
{
"name": "Liaoning",
"value": 62055.0
},
{
"name": "Tianjin",
"value": 64101.0
},
{
"name": "Inner Mongolia",
"value": 67454.0
},
{
"name": "Guangxi",
"value": 79283.0
},
{
"name": "Shaanxi",
"value": 106005.0
},
{
"name": "Hebei",
"value": 106109.0
},
{
"name": "Fujian",
"value": 116024.0
},
{
"name": "Xinjiang",
"value": 136161.0
},
{
"name": "Chongqing",
"value": 180853.0
},
{
"name": "Sichuan",
"value": 193293.0
},
{
"name": "Jiangsu",
"value": 202713.0
},
{
"name": "Beijing",
"value": 235333.0
},
{
"name": "Shanghai",
"value": 241459.0
},
{
"name": "Shandong",
"value": 245706.0
},
{
"name": "Heilongjiang",
"value": 259973.0
},
{
"name": "Jiangxi",
"value": 289122.0
},
{
"name": "Anhui",
"value": 306312.0
},
{
"name": "Hunan",
"value": 316247.0
},
{
"name": "Zhejiang",
"value": 393984.0
},
{
"name": "Henan",
"value": 395577.0
},
{
"name": "Guangdong",
"value": 516608.0
},
{
"name": "Hong Kong",
"value": 834002.0
},
{
"name": "Hubei",
"value": 20670801.0
}
],
"roam": true,
"aspectScale": 0.75,
"nameProperty": "name",
"selectedMode": false,
"zoom": 1,
"mapValueCalculation": "sum",
"showLegendSymbol": true,
"emphasis": {}
}
],
"legend": [
{
"data": [
"\u786e\u8bca"
],
"selected": {
"\u786e\u8bca": true
},
"show": true,
"padding": 5,
"itemGap": 10,
"itemWidth": 25,
"itemHeight": 14
}
],
"tooltip": {
"show": true,
"trigger": "item",
"triggerOn": "mousemove|click",
"axisPointer": {
"type": "line"
},
"showContent": true,
"alwaysShowContent": false,
"showDelay": 0,
"hideDelay": 100,
"textStyle": {
"fontSize": 14
},
"borderWidth": 0,
"padding": 5
},
"title": [
{
"text": "\u75ab\u60c5\u56fe-\u786e\u8bca\u4eba\u6570",
"padding": 5,
"itemGap": 10
}
],
"visualMap": {
"show": true,
"type": "piecewise",
"min": 0,
"max": 100,
"inRange": {
"color": [
"#50a3ba",
"#eac763",
"#d94e5d"
]
},
"calculable": true,
"inverse": false,
"splitNumber": 5,
"orient": "vertical",
"showLabel": true,
"itemWidth": 20,
"itemHeight": 14,
"borderWidth": 0,
"pieces": [
{
"min": 1000,
"label": ">1000\u4eba",
"color": "#6F171F"
},
{
"min": 500,
"max": 1000,
"label": "500-1000\u4eba",
"color": "#C92C34"
},
{
"min": 100,
"max": 499,
"label": "100-499\u4eba",
"color": "#E35B52"
},
{
"min": 10,
"max": 99,
"label": "10-99\u4eba",
"color": "#F39E86"
},
{
"min": 1,
"max": 9,
"label": "1-9\u4eba",
"color": "#FDEBD0"
}
]
}
};
chart_c11071484495441fb56547337c4c9980.setOption(option_c11071484495441fb56547337c4c9980);
</script>
</body>
</html>

Loading…
Cancel
Save