jwass / mplleaflet

Easily convert matplotlib plots from Python into interactive Leaflet web maps.
BSD 3-Clause "New" or "Revised" License
521 stars 76 forks source link

Mplleaflet not showing plot . #66

Open sameerCoder opened 5 years ago

sameerCoder commented 5 years ago

Hi, I have tripcolor trianulation plot wave plot and that plot i need to overlap with background as google map with zoom function , so i tried mplleaflet but the tripcolor plot is not coming over the map. can you tell me how to do this.

%matplotlib inline import matplotlib.pyplot as plt from scipy.io import loadmat import mplleaflet import datetime import pandas as pd from dateutil.parser import parse

import matplotlib as mpl

from pylab import *

import numpy as np import os

fig=plt.figure()

fig, ax = plt.subplots(figsize=(13, 13), subplot_kw=dict(projection=projection))

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 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()

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")
#pp = plt.tripcolor(triang, z1,cmap='jet')
# ax.tripcolor()
#     #
#     # plt.suptitle('Significant Wave Height', fontname='Comic Sans MS', fontweight='bold', fontsize=12, color="red")
#     # plt.title("Experimental forecast for " + str(hr) + ':' + '0' + str(mi) + ' ' + str(d) + '-' + 'Jan' + '-' + str(yr),
#     #           fontsize=10, fontname='sans-serif', color="green")
#     #
#     # plt.savefig(varname + '.png', dpi=500)

# plt.colorbar()
#plt.show()
#mplleaflet.show()
fig, ax = plt.subplots()
tp=ax.tripcolor(triang, z1, vmin=0, vmax=2)
#mplleaflet.display(fig=tp)
mplleaflet.display()
mplleaflet.show()
break