代码拉取完成,页面将自动刷新
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
@Author :hhx
@Date :2022/5/15 11:02
@Description :
"""
import os
import numpy as np
import matplotlib.pyplot as plt
import datetime
plt.rcParams['font.sans-serif'] = ['SimHei'] # 用来正常显示中文标签
plt.rcParams['axes.unicode_minus'] = False
def preprocess_div(data1):
data = data1.ravel()
id = np.where((data.astype('str') == 'nan'))
data = np.delete(data, id)
return data
def getIndexMean(data, idx):
cpList = ['201811', '202010', '202112']
tempp = []
temp = []
# print(data)
for i in data:
if i not in idx:
temp.append(i)
else:
tempp.append(temp)
temp = [i]
print(tempp)
def formatnum(n):
if n < 10:
return '0' + str(n)
return str(n)
def CreateVertex(date1, date2):
"""创建节点"""
VertexList = []
year1, month1 = date1
year2, month2 = date2
for year in range(year1, year2 + 1):
if year == year1:
for month in range(month1, 13):
VertexList.append('{}{}'.format(year, formatnum(month)))
elif year == year2:
for month in range(1, month2 + 1):
VertexList.append('{}{}'.format(year, formatnum(month)))
else:
for month in range(1, 13):
VertexList.append('{}{}'.format(year, formatnum(month)))
return VertexList
if __name__ == '__main__':
changjiang = [6, 10, 17, 72] # changjiang
# changjiang = [6, 33, 56, 72] # luoyang
# changjiang = [6, 22, 44, 72]
loc = 'changjiangcunchu'
start = (2016, 7)
end = (2021, 12)
VertexList = CreateVertex(start, end) # 创建节点
Veg = []
SI = []
WB = []
BLI = []
for i in range(1, 5):
path = 'result/' + loc + '_' + str(i) + '.npy'
data = np.load(path)
res = []
for j in range(0, len(changjiang) - 1):
d1 = data[changjiang[j] - 6:changjiang[j + 1] - 6]
res.append([np.mean(d1)])
if i == 1:
Veg = res
elif i == 2:
SI = res
elif i == 3:
WB = res
else:
BLI = res
print(Veg)
print(SI)
print(WB)
print(BLI)
for i in range(len(WB) - 1):
if WB[i + 1][0] - WB[i][0] >= 0:
SI[i + 1][0] += WB[i + 1][0] - WB[i][0]
WB[i + 1][0] = WB[i][0]
print(Veg)
print(SI)
print(WB)
print(BLI)
VegList = []
SIList = []
WBList = []
BLIList = []
date = [datetime.datetime.strptime(x, "%Y%m") for x in VertexList]
res = []
for j in range(0, len(changjiang) - 1):
res.extend(Veg[j] * (changjiang[j + 1] - changjiang[j]))
plt.plot(date, res, color='green', label='植被')
plt.scatter(date, res, color='green', s=5)
res = []
for j in range(0, len(changjiang) - 1):
res.extend(SI[j] * (changjiang[j + 1] - changjiang[j]))
plt.plot(date, res, color='gray', label='不透水面')
plt.scatter(date, res, color='gray', s=5)
res = []
for j in range(0, len(changjiang) - 1):
res.extend(WB[j] * (changjiang[j + 1] - changjiang[j]))
plt.plot(date, res, color='blue', label='水体')
plt.scatter(date, res, color='blue', s=5)
res = []
for j in range(0, len(changjiang) - 1):
res.extend(BLI[j] * (changjiang[j + 1] - changjiang[j]))
plt.plot(date, res, color='#DAA520', label='裸地')
plt.scatter(date, res, color='#DAA520', s=5)
plt.axhline(0, c='black', ls='--')
plt.title('长江存储')
plt.legend(fontsize=12)
plt.show()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。