from mpl_toolkits.basemap import Basemap
import matplotlib.pyplot as plt
import matplotlib.colors as colors
from numpy import array
from numpy import max


map = Basemap(llcrnrlon=-0.5,llcrnrlat=39.8,urcrnrlon=4.,urcrnrlat=43.,
             resolution='i', projection='tmerc', lat_0 = 39.5, lon_0 = 1)


map.readshapefile('../sample_files/lightnings', 'lightnings')

x = []
y = []
c = []

for info, lightning in zip(map.lightnings_info, map.lightnings):
    x.append(lightning[0])
    y.append(lightning[1])
    
    if float(info['amplitude']) < 0:
        c.append(-1 * float(info['amplitude']))
    else:
        c.append(float(info['amplitude']))
    
plt.figure(0)

map.drawcoastlines()
map.readshapefile('../sample_files/comarques', 'comarques')

map.hexbin(array(x), array(y))

map.colorbar(location='bottom')



plt.figure(1)

map.drawcoastlines()
map.readshapefile('../sample_files/comarques', 'comarques')

map.hexbin(array(x), array(y), gridsize=20, mincnt=1, cmap='summer', bins='log')

map.colorbar(location='bottom', format='%.1f', label='log(# lightnings)')



plt.figure(2)

map.drawcoastlines()
map.readshapefile('../sample_files/comarques', 'comarques')

map.hexbin(array(x), array(y), gridsize=20, mincnt=1, cmap='summer', norm=colors.LogNorm())

cb = map.colorbar(location='bottom', format='%d', label='# lightnings')

cb.set_ticks([1, 5, 10, 15, 20, 25, 30])
cb.set_ticklabels([1, 5, 10, 15, 20, 25, 30])




plt.figure(3)

map.drawcoastlines()
map.readshapefile('../sample_files/comarques', 'comarques')

map.hexbin(array(x), array(y), C = array(c), reduce_C_function = max, gridsize=20, mincnt=1, cmap='YlOrBr', linewidths=0.5, edgecolors='k')

map.colorbar(location='bottom', label='Mean amplitude (kA)')


plt.show()
[((8, 6, 9, 73), 'mpl_toolkits.basemap.Basemap', 'Basemap', (), '', False, 'from mpl_toolkits.basemap import Basemap\n'), ((27, 0, 27, 13), 'matplotlib.pyplot.figure', 'plt.figure', ({(27, 11, 27, 12): '(0)'}, {}), '(0)', True, 'import matplotlib.pyplot as plt\n'), ((38, 0, 38, 13), 'matplotlib.pyplot.figure', 'plt.figure', ({(38, 11, 38, 12): '(1)'}, {}), '(1)', True, 'import matplotlib.pyplot as plt\n'), ((49, 0, 49, 13), 'matplotlib.pyplot.figure', 'plt.figure', ({(49, 11, 49, 12): '(2)'}, {}), '(2)', True, 'import matplotlib.pyplot as plt\n'), ((64, 0, 64, 13), 'matplotlib.pyplot.figure', 'plt.figure', ({(64, 11, 64, 12): '(3)'}, {}), '(3)', True, 'import matplotlib.pyplot as plt\n'), ((74, 0, 74, 10), 'matplotlib.pyplot.show', 'plt.show', ({}, {}), '()', True, 'import matplotlib.pyplot as plt\n'), ((32, 11, 32, 19), 'numpy.array', 'array', ({(32, 17, 32, 18): 'x'}, {}), '(x)', False, 'from numpy import array\n'), ((32, 21, 32, 29), 'numpy.array', 'array', ({(32, 27, 32, 28): 'y'}, {}), '(y)', False, 'from numpy import array\n'), ((43, 11, 43, 19), 'numpy.array', 'array', ({(43, 17, 43, 18): 'x'}, {}), '(x)', False, 'from numpy import array\n'), ((43, 21, 43, 29), 'numpy.array', 'array', ({(43, 27, 43, 28): 'y'}, {}), '(y)', False, 'from numpy import array\n'), ((54, 11, 54, 19), 'numpy.array', 'array', ({(54, 17, 54, 18): 'x'}, {}), '(x)', False, 'from numpy import array\n'), ((54, 21, 54, 29), 'numpy.array', 'array', ({(54, 27, 54, 28): 'y'}, {}), '(y)', False, 'from numpy import array\n'), ((69, 11, 69, 19), 'numpy.array', 'array', ({(69, 17, 69, 18): 'x'}, {}), '(x)', False, 'from numpy import array\n'), ((69, 21, 69, 29), 'numpy.array', 'array', ({(69, 27, 69, 28): 'y'}, {}), '(y)', False, 'from numpy import array\n'), ((54, 74, 54, 90), 'matplotlib.colors.LogNorm', 'colors.LogNorm', ({}, {}), '()', True, 'import matplotlib.colors as colors\n'), ((69, 35, 69, 43), 'numpy.array', 'array', ({(69, 41, 69, 42): 'c'}, {}), '(c)', False, 'from numpy import array\n')]