我想在Folium Map上绘制我的Trigulation图。我的Tripcolor PLot没有显示在Folium Map中。请Pzzzz告诉我如何在FOLIUM MAP PLOT中使用TRIPCOLOR。
我已经绘制了Folium,Folium地图正变得非常漂亮。我想在其中绘制我的Tripcolor函数,然后就不绘制Tripcolor了。如何在Folium库中绘制Tripcolor函数。
import matplotlib.pyplot as plt
from scipy.io import loadmat
import datetime
import pandas as pd
from dateutil.parser import parse
import numpy as np
from scipy.spatial import Delaunay
import mpl_toolkits.mplot3d.axes3d
from datetime import timedelta
import matplotlib.tri as mtri
from mpl_toolkits.basemap import Basemap
%matplotlib inline
import folium
from folium.features import CustomIcon
import os
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_table('fort.ele', delim_whitespace=True, names=('A',
'B', 'C', 'D'), usecols=[1, 2, 3], skiprows=1,
dtype={'D': np.int})
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 int(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()
# map = Basemap(llcrnrlon=40, llcrnrlat=-30, urcrnrlon=120, urcrnrlat=30,
# resolution='h') # India location map .
# map.drawstates()
tri_sub = tri_new.apply(lambda x: x - 1)
triang = mtri.Triangulation(x, y, triangles=tri_sub)
pp = plt.tripcolor(triang, z1, cmap='jet', vmin=0.0, vmax="0.5")
# plt.xlabel(" \n\n(Longitude .) ", fontweight='bold', fontsize=12, color="red")
# plt.ylabel(" \n\n(Latitude .) ", fontweight='bold', fontsize=12, color="red",multialignment='center')
# plt.xticks(range(int(86.7), int(87.8)))
# plt.yticks(range(int(20.7), int(21.7)))
m = folium.Map(location=[17, 80], zoom_start=5, tiles='Stamen Terrain')
url = 'http://leafletjs.com/examples/custom-icons/{}'.format
icon_image = url('leaf-red.png')
shadow_image = url('leaf-shadow.png')
#TRIGulation Code is below .
#TRIPCOLOR ,
# How to use This Tripcolor in Folium .
tri_sub = tri_new.apply(lambda x: x - 1)
triang = mtri.Triangulation(x, y, triangles=tri_sub)
pp = m.tripcolor(triang, z1, cmap='jet',vmin=0.0,vmax="0.5")
m.add_child(pp)
# map.colorbar(extend='both', aspect=50, shrink=1, pad=0.5, anchor=(0.5, 1.0))
#plt.savefig(varname + '.png', dpi=500)
m.save('customicon.html')
m
# def onpress(event):
# if event.button != 1:
# return
# x, y = event.xdata, event.ydata
# axzoom.set_xlim(x - 0.1, x + 0.1)
# axzoom.set_ylim(y - 0.1, y + 0.1)
# figzoom.canvas.draw()
#
#
# figsrc.canvas.mpl_connect('button_press_event', onpress)
#m.add_child(marker)
#m.save(os.path.join('results', 'CustomIcon.html'))
plt.show()
break