-
Notifications
You must be signed in to change notification settings - Fork 178
Cartopy Plot is Very Slow compare to Basemap. #92
Description
Hi,
When i increase the lat long range for plotting in Cartopy with zoom level 10 or more than this cartopy plot is taking several hours to plot a single image. I want to increase the zoom level so that states should visible nicely and i want to add zoom features also in this plot .
How to reduce the time of this cartopy plot .
My Cartopy Plot code is given below .
`
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
%matplotlib inline
import matplotlib.pyplot as plt
from matplotlib.pyplot import figure, show
import cartopy.crs as ccrs
from cartopy.io import shapereader
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
import cartopy.io.img_tiles as cimgt
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})
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)
def make_map(projection=ccrs.PlateCarree()):
fig, ax = plt.subplots(figsize=(13, 13),subplot_kw=dict(projection=projection))
#gl = ax.gridlines(draw_labels=True,linestyle='--',linewidth=2)
gl = ax.gridlines(draw_labels=False)
ax.grid(False)
gl.xlabels_top = gl.ylabels_right = False
gl.xformatter = LONGITUDE_FORMATTER
gl.yformatter = LATITUDE_FORMATTER
return fig, ax
extent = [70, 93, 0, 26]
request = cimgt.GoogleTiles(url = 'https://cartodb-basemaps-4.global.ssl.fastly.net/rastertiles/voyager/{Z}/{X}/{Y}.png')
fig, ax = make_map()
tpc = ax.tripcolor(triang,z1,vmin = 0, vmax = 2)
ax.set_extent(extent)
ax.add_image(request, 9,interpolation='spline36')
ax.coastlines('50m')
fig.colorbar(tpc,extend='both')
plt.show()
break`