这些地图的图形如何创建调色板

时间:2019-06-09 03:36:36

标签: python matplotlib maps cartography

i need these palette in my map我需要绘制一个地图,并且调色板是离散的,第一个代码找到它和一个离散的调色板,但这不像添加到我的地图的代码中,这是第二个代码。 / p>

`# THE FIRST CODE

fig, ax = plt.subplots(figsize=(6, 1))
fig.subplots_adjust(bottom=0.5)

cmap = mpl.colors.ListedColormap(['royalblue', 'cyan',
                                  'yellow', 'orange'])
cmap.set_over('red')
cmap.set_under('blue')

bounds = [-1.0, -0.5, 0.0, 0.5, 1.0]
norm = mpl.colors.BoundaryNorm(bounds, cmap.N)
cb3 = mpl.colorbar.ColorbarBase(ax, cmap=cmap,
                                norm=norm,
                                boundaries=[-10] + bounds + [10],
                                extend='both',
                                extendfrac='auto',
                                ticks=bounds,
                                spacing='uniform',
                                orientation='horizontal')
cb3.set_label('Custom extension lengths, some other units')

    #SECOND CODE FOR MY Map
   `lon_0 = lons.mean()
lat_0 = lats.mean()
m= Basemap(projection='merc',llcrnrlat=min_lat,urcrnrlat=max_lat,\
            llcrnrlon=min_lon,urcrnrlon=max_lon,resolution='l')
lon, lat = np.meshgrid(lons, lats)
xi, yi = m(lon, lat)`
    fig = plt.figure(figsize=(10,20))
    m.drawparallels(np.arange(-20., 40., 3.), labels=[1,0,0,0], fontsize=12)# Latitude lines every 5 degrees from -5 to 15. Left zone
    m.drawmeridians(np.arange(-90., -40., 3.), labels=[0,0,0,1], fontsize=12) # longitute lines every 5 degrees from -80 to -45. Down zone

    # Add Coastlines, States, and Country Boundaries
    m.drawcoastlines(linewidth= 1, color='black')
    #m.drawstates()
    m.drawcountries(linewidth= 1, color='black')
    m.readshapefile('/home/shared/shapes/bogota/Localidades_Lat_lon', 'Localidades_Lat_lon')

    cs = m.pcolormesh(xi, yi, (Eagricola.variables['E_PM25J'][0,0,:,:]), cmap=plt.cm.Blues, vmin=0, vmax=np.percentile(np.mean(EBase.variables['E_PM25J'][:,0,:,:], axis=0),90.5))
    ## Add Colorbar
    plt.title('Emisiones Agricola', fontsize=20)
    cbar = m.colorbar(cs, location='right', pad="2%", size="5%", extend='max')
    cbar.set_label("PM2.5 " + "$ug /m^2 s^1$", fontsize=1)
    plt.show()`

0 个答案:

没有答案