Question

I need to plot data of rain summas (from satellite observations) onto a map from grib2 files. Finally I managed to load the data via text files into numpy arrays and tie it with picture coordinates using Basemap. But problem is that Python do not put the coloured points from the data, but tends to draw lines between neighbouring points in data field, so the plot looks ugly. I do not see the source of the problem.

Fragments of my code are:

import numpy as np
import matplotlib
matplotlib.use('Agg')
from scipy import *
from pylab import *
from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
from mpl_toolkits.basemap import cm

After that I read the data needed and produce 3 numpy arrays with shapes approximately (100000, 2), which contain respectively latitude, longitude, in degrees and the value of each data point. I visualize it using these commands:

def joonista(lats,lons,value,nimi,clevs,koloriit):

---------fragment of described reshaping (not shown), produces arrays "lats", "lons", "value"------------

map=Basemap(projection='aea',lat_1=30,lat_2=50,lat_0=45,lon_0=0,llcrnrlon=-30,llcrnrlat=20,urcrnrlon=80,urcrnrlat=53,resolution='l',)

x, y = map(lons, lats)
map.drawcoastlines(linewidth=0.17,color='0.7')
map.drawcountries(linewidth=0.17,color='0.7')
map.drawmeridians(np.arange(-50,60,5),linewidth=0.17,color='0.7',labels=[False,False,False,True])
map.drawparallels(np.arange(-25, 70, 5),linewidth=0.17,color='0.7',labels=[True,False,False,False])
varvid=mpl.colors.ListedColormap(koloriit)
norm = mpl.colors.BoundaryNorm(clevs,varvid.N)
cs = map.pcolormesh(x,y,value,cmap=varvid,norm=norm)
savefig(nimi,dpi=300)
plt.clf()

joonista(latA,lonA,valueA,'h05',[-1,0.00001,0.001,0.01,0.1,0.3,0.5,1,2,3,4,5,6,7,8,9,10,11,12,13],['k','c','#a0fff9','#00b354','#69b300','#97ff03','#C2524D','#FF7500','#b3a900','#fff551','#515bff','#45adff','#da000d','#ff2a36','#ffa0a5','#f003ff','#f778ff','0.5','0.75'])
joonista(latB,lonB,valueB,'h04',[-1,0.0000000000001,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18],['k','c','#a0fff9','#00b354','#69b300','#97ff03','#C2524D','#FF7500','#b3a900','#fff551','#515bff','#45adff','#da000d','#ff2a36','#ffa0a5','#f003ff','#f778ff','0.5','0.75'])

Here is an example picture:

Example

I would be grateful, if I am told how to solve this problem.

Aleksei

Was it helpful?

Solution

Using Joe Kington recommendation, I replaced command

cs=map.pcolormesh(x,y,value,cmap=varvid,norm=norm)

by command

cs=plt.scatter(x,y,c=value,s=0.6, edgecolors='none',marker=',',cmap=varvid,norm=norm)

which well visualises precipitation distribution.

Thanks for assistance!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top