def basemap_earth(self): data = np.array(self, dtype=float) lat = data['lat'] lon = data['lon'] lon, lat = mp.meshgrid(lon, lat) 2m_mean_temp = data['air'] fig = plt.figure(figsize=(10, 8)) m = Basemap(projection='cyl', resolution='c', lat_0=0, lon_0=0) m.fillcontinents(color="#FAFAFA", lake_color="#FAFAFA") m.drawmapboundary(fill_color="#FAFAFA") m.drawcoastlines() plt. return draw_map(m)
ffrom mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt fig = plt.gcf() # fig.set_size_inches(10, 15) # Google map map = Basemap( llcrnrlon= -80.080208, llcrnrlat= 41.154397, urcrnrlon= -80.077010, urcrnrlat= 41.155810, epsg=2271) map.arcgisimage(service='World_Imagery', verbose= True) # Scatter of gps data in lat lon # plt.title("Latitude vs. Longitude") plt.show() fig.savefig("Map.png", bbox_inches='tight', pad_inches = -.1, dpi=220)
notglon = np.append(notglon, tslon[i][np.array(ts[i])>= LI0[i]]) notglat = np.append(notglat, tslat[i][np.array(ts[i])>= LI0[i]]) #%% Make the plot fig, ax = plt.subplots(figsize=(12,8)) ACCloc = np.load('ACClocation.npz') acclat = ACCloc['acclat'][:] acclon = ACCloc['acclon'][:] acclat = running_mean_circular(acclat,150)# To get a running_mean over circular data plt.subplot2grid((16, 8), (0, 0), colspan=4, rowspan=12) m = Basemap(projection='splaea',boundinglat=-30,lon_0=90,resolution=resolution)#north pole: 'nplaea', south pole: 'spaeqd' m.drawcoastlines() m.drawmapboundary(fill_color='w')#black') m.fillcontinents(color='grey')#, lake_color='lightskyblue') m.drawparallels(np.arange(-70, 70, 20), labels=[True, False, False, False]) m.drawmeridians(np.arange(0, 361, 45), labels=[False, False, False, True]) plt.title('(a) ' + zondata['variables'][specie_number][:-3],**ifont) aclon, aclat = m(acclon, acclat) xzon, yzon = m(zonlon, zonlat) xadv, yadv = m(glon, glat) xadv2, yadv2 = m(notglon, notglat) cmap = plt.get_cmap('Blues') plt.scatter(xadv, yadv, c=redcolor, label='backtracked cold tail', s=15, alpha=0.3)#, zorder=4
algoritmo.pyfrom mpl_toolkits.basemap import Basemap import matplotlib.pyplot as plt import numpy as np from numpy import meshgrid import pandas as pd import math plt.figure(figsize=(48,24)) m = Basemap(projection='mill',llcrnrlat=25,urcrnrlat=33,llcrnrlon=-115,urcrnrlon=-107,resolution='i') #%% read txt file data = pd.read_csv('data/2017-09-25.csv') #%% calculate U and V vectors def calculateU(windSpeed, windDirection): ''' Generate U vector ''' return windSpeed * math.cos(windDirection) def calculateV(windSpeed, windDirection): ''' Generate V vector ''' return windSpeed * math.sin(windDirection) #%% cut info data = data.loc[data['Long'] > -115.0] data = data.loc[data['Long'] < -107.0]
m.plot(lons, lats, 'bo') plt.draw() # SAVE AS 2D ARRAY... pre land-masking np.savez('test_grid', lats, lons) MEEP += 1 MEEP = 0 # approximate radius of earth in km R = 6378.13 fig = plt.figure(figsize=(11.7, 8.3)) plt.subplots_adjust(left=0.05, right=0.95, top=0.90, bottom=0.05, wspace=0.15, hspace=0.05) ax = plt.subplot(111) m = Basemap(resolution='l') m.drawmapboundary(fill_color='azure') m.fillcontinents(color='palegoldenrod', lake_color='azure') m.drawcoastlines() grid_res = input("Grid resolution in km: ") click = Click(ax, grid_gen) #fig.canvas.mpl_connect("button_press_event", onclick) plt.show()
def value6_map1(xCoord, yCoord, sList): symbolSize=5 s = np.asarray(sList) maxValue = np.amax(s) minValue = np.amin(s) if abs(maxValue) >= abs(minValue): absRange = abs(maxValue) else: absRange = abs(minValue) value1 = -(absRange/3*2) value2 = -(absRange/3) value3 = 0 value4 = absRange/3 value5 = absRange/3*2 group1 = np.ma.masked_where(s > value1, s) group2 = np.ma.masked_where(np.logical_or(s< value1, s> value2), s) group3 = np.ma.masked_where(np.logical_or(s< value2, s> value3), s) group4 = np.ma.masked_where(np.logical_or(s< value3, s> value4), s) group5 = np.ma.masked_where(np.logical_or(s< value4, s> value5), s) group6 = np.ma.masked_where(s < value5, s) oneGroup1 = [] oneGroup2 = [] oneGroup3 = [] oneGroup4 = [] oneGroup5 = [] oneGroup6 = [] for grp1 in group1: if grp1 !='--': oneGroup1.append(symbolSize) else: oneGroup1.append(0) for grp2 in group2: if grp2 !='--': oneGroup2.append(symbolSize) else: oneGroup2.append(0) for grp3 in group3: if grp3 !='--': oneGroup3.append(symbolSize) else: oneGroup3.append(0) for grp4 in group4: if grp4 !='--': oneGroup4.append(symbolSize) else: oneGroup4.append(0) for grp5 in group5: if grp5 !='--': oneGroup5.append(symbolSize) else: oneGroup5.append(0) for grp6 in group6: if grp6 !='--': oneGroup6.append(symbolSize) else: oneGroup6.append(0) fig = plt.figure(figsize=(12, 10)) ax = fig.add_subplot(1,1,1) legendValue1 = str(round(value1,2)) legendValue2 = str(round(value2,2)) legendValue3 = str(round(value3,2)) legendValue4 = str(round(value4,2)) legendValue5 = str(round(value5,2)) rangeList = bm.addBasemap(bm.basemapRange, bm.basemapPolygonList, bm.basemapLineList, bm.basemapPointList, bm.basemapElements, ax) ## Setting for ax ax.set_xlim(rangeList[0],rangeList[1]) ax.set_ylim(rangeList[2],rangeList[3]) ax.scatter(0,0, s=0, c='w', label = 'Estimates') if oneGroup1.count(0) != len(oneGroup1): ax.scatter(xCoord,yCoord, s= oneGroup1, c='#3300CC', edgecolor='none', label = 'less than ' + legendValue1) if oneGroup2.count(0) != len(oneGroup2): ax.scatter(xCoord,yCoord, s= oneGroup2, c='#3333FF', edgecolor='none', label = legendValue1 + ' - ' + legendValue2) if oneGroup3.count(0) != len(oneGroup3): ax.scatter(xCoord,yCoord, s= oneGroup3, c='#33CCFF', edgecolor='none', label = legendValue2 + ' - ' + legendValue3) if oneGroup4.count(0) != len(oneGroup4): ax.scatter(xCoord,yCoord, s= oneGroup4, c='#FFCC00', edgecolor='none', label = legendValue3 + ' - ' + legendValue4) if oneGroup5.count(0) != len(oneGroup5): ax.scatter(xCoord,yCoord, s= oneGroup5, c='#FF6600', edgecolor='none', label = legendValue4 + ' - ' + legendValue5) if oneGroup6.count(0) != len(oneGroup6): ax.scatter(xCoord,yCoord, s= oneGroup6, c='#FF0000', edgecolor='none', label = 'more than '+legendValue5) ax.legend(loc=3, ncol=1, fontsize=7, bbox_to_anchor=(-0.15,-0.15), markerscale=3.0, fancybox = True, scatterpoints = 1) return fig, ax
def map2(xCoord, yCoord, estValues, tValues, correctedT, rangeValue): #correctedT : double determined by year variable #rangeValue : valueList = [] for ind, value in enumerate(xCoord): # print value # print type(yCoord[ind]) tempArray = [float(value[0]), float(yCoord[ind]), float(estValues[ind]), float(tValues[ind])] valueList.append(tempArray) newValueList = [] index = 0 for value in valueList: if abs(value[3]) > abs(correctedT): newValueList.append(value) index+=1 newxCoord = [] newyCoord = [] newEstValues = [] newTValues = [] for newValue in newValueList: newxCoord.append(newValue[0]) newyCoord.append(newValue[1]) newEstValues.append(newValue[2]) newTValues.append(newValue[3]) symbolSize=15 sEst = np.asarray(newEstValues) absRange = rangeValue value1 = -(absRange/3*2) value2 = -(absRange/3) value3 = 0 value4 = absRange/3 value5 = absRange/3*2 group1Est = np.ma.masked_where(sEst > value1, sEst) group2Est = np.ma.masked_where(np.logical_or(sEst< value1, sEst> value2), sEst) group3Est = np.ma.masked_where(np.logical_or(sEst< value2, sEst> value3), sEst) group4Est = np.ma.masked_where(np.logical_or(sEst< value3, sEst> value4), sEst) group5Est = np.ma.masked_where(np.logical_or(sEst< value4, sEst> value5), sEst) group6Est = np.ma.masked_where(sEst < value5, sEst) oneGroup1Est = [] oneGroup2Est = [] oneGroup3Est = [] oneGroup4Est = [] oneGroup5Est = [] oneGroup6Est = [] for grp1 in group1Est: if grp1 !='--': oneGroup1Est.append(symbolSize) else: oneGroup1Est.append(0) for grp2 in group2Est: if grp2 !='--': oneGroup2Est.append(symbolSize) else: oneGroup2Est.append(0) for grp3 in group3Est: if grp3 !='--': oneGroup3Est.append(symbolSize) else: oneGroup3Est.append(0) for grp4 in group4Est: if grp4 !='--': oneGroup4Est.append(symbolSize) else: oneGroup4Est.append(0) for grp5 in group5Est: if grp5 !='--': oneGroup5Est.append(symbolSize) else: oneGroup5Est.append(0) for grp6 in group6Est: if grp6 !='--': oneGroup6Est.append(symbolSize) else: oneGroup6Est.append(0) legendValue1 = str(round(value1,2)) legendValue2 = str(round(value2,2)) legendValue3 = str(round(value3,2)) legendValue4 = str(round(value4,2)) legendValue5 = str(round(value5,2)) fig = plt.figure(figsize=(9, 7.5)) ax = fig.add_subplot(1,1,1) rangeList = bm.addBasemap(bm.basemapRange, bm.basemapPolygonList, bm.basemapLineList, bm.basemapPointList, bm.basemapElements, ax) ## Setting for ax ax.set_xlim(rangeList[0],rangeList[1]) ax.set_ylim(rangeList[2],rangeList[3]) ax.scatter(0,0, s=0, c='w', label = 'Estimates') if oneGroup1Est.count(0) != len(oneGroup1Est): ax.scatter(newxCoord,newyCoord, s= oneGroup1Est, c='#3300CC', edgecolor='none', label = 'less than ' + legendValue1) if oneGroup2Est.count(0) != len(oneGroup2Est): ax.scatter(newxCoord,newyCoord, s= oneGroup2Est, c='#3333FF', edgecolor='none', label = legendValue1 + ' - ' + legendValue2) if oneGroup3Est.count(0) != len(oneGroup3Est): ax.scatter(newxCoord,newyCoord, s= oneGroup3Est, c='#33CCFF', edgecolor='none', label = legendValue2 + ' - ' + legendValue3) if oneGroup4Est.count(0) != len(oneGroup4Est): ax.scatter(newxCoord,newyCoord, s= oneGroup4Est, c='#FFCC00', edgecolor='none', label = legendValue3 + ' - ' + legendValue4) if oneGroup5Est.count(0) != len(oneGroup5Est): ax.scatter(newxCoord,newyCoord, s= oneGroup5Est, c='#FF6600', edgecolor='none', label = legendValue4 + ' - ' + legendValue5) if oneGroup6Est.count(0) != len(oneGroup6Est): ax.scatter(newxCoord,newyCoord, s= oneGroup6Est, c='#FF0000', edgecolor='none', label = 'more than '+legendValue5) # ax.legend(loc=3, ncol=1, fontsize=9, bbox_to_anchor=(0.,-0.1), markerscale=3.0, fancybox = True, scatterpoints = 1) return fig, ax