我在matplotlib中有Tripcolor代码,我正在尝试使用Google Map作为背景来绘制此图像,但我正在使用gmaps库,但无法成功进行绘制。在gmaps中添加图层时,他们说poly实例必须是列表,然后我尝试将tripcolor输出为列表,然后这也无法正常工作。 在将pp作为列表时,由于polycollection无法迭代,因此会出现其他一些错误。 Plzz让我知道了如何将我的Tripcolor与gmaps一起应用并成功绘制它。 TIA。 我收到错误: TraitError:Polygon实例的“路径”特征必须是列表,但是指定了“ matplotlib.collections.PolyCollection”类的值(即)。
gmaps matplotlib 三色 多收集
import matplotlib.pyplot as plt
from scipy.io import loadmat
import datetime
import pandas as pd
from dateutil.parser import parse
# import matplotlib as mpl
# from pylab import *
import numpy as np
import os
import gmaps
gmaps.configure(api_key='AIzaSyBPIc-Z0WGhaPRmeyNW0gZ7a6Z5OV-n1WI')
os.environ['PROJ_LIB'] = r'C:\Users\walps\Anaconda3\pkgs\proj4-5.2.0-
ha925a31_1\Library\share'
from datetime import timedelta
import matplotlib.tri as mtri
datamat = loadmat('IOEC_ECM2017_BC.mat')
Xp = datamat['Xp']
Yp = datamat['Yp']
strt = datetime.datetime(2017, 1, 11, 0, 0)
end = datetime.datetime(2017, 1, 21, 0, 0)
numdays = 3
def perdelta(strt, end, delta):
curr = strt
while curr < end:
yield curr
curr += delta
# Read element file
# data = pd.read_table('fort.ele',delim_whitespace=True,names=
('A','B','C','D'))
tri_new = pd.read_csv('fort.ele', delim_whitespace=True, names=('A',
'B', 'C', 'D'), usecols=[1, 2, 3], skiprows=1,
dtype={'D': np.int})
# data1=data[['B','C','D']]
# tri=data1[1:]
dateList = []
for result in perdelta(strt, strt + timedelta(days=2),
timedelta(hours=3)):
dat = result
# print(result)
dt = parse(str(dat))
yr = dt.year
mn = dt.month
d = dt.day
hr = dt.hour
mi = dt.minute
# print(y,mn,d,hr,mi)
if hr < 10:
# d='0'+str(d)
hr = '0' + str(hr)
else:
d = str(d)
hr = str(hr)
if d < 10:
d = '0' + str(d)
else:
d = str(d)
varname = 'Hsig_' + str(yr) + '0' + str(mn) + str(d) + '_' + hr +
'0000'
print(varname)
x = Xp.flatten()
y = Yp.flatten()
z = datamat[varname]
z1 = z.flatten()
tri_sub = tri_new.apply(lambda x: x - 1)
triang = mtri.Triangulation(x, y, triangles=tri_sub)
pp = plt.tripcolor(triang, z1)
# x_list=[]
# y_list=[]
# z_list=[]
# pp_list=[]
# pplist=list(pp)
# print(pplist)
# break
# for xx in range (len(x)):
# x_list.append(xx)
# for yy in range(len(y)):
# y_list.append(yy)
# for zz in range (len(z)):
# z_list.append(zz)
# for ppp in range(len(pp)):
# pp_list.append(ppp)
fig = gmaps.figure()
#drawing= gmaps.Polygon(pp_list)
drawing=gmaps.Polygon(pp)
fig.add_layer(drawing)
fig
break
我希望三色图应重叠在Google地图上。 背景应该是具有缩放功能的Google地图。