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()
[((162, 293), 'mpl_toolkits.basemap.Basemap', 'Basemap', ([], {'llcrnrlon': '(-0.5)', 'llcrnrlat': '(39.8)', 'urcrnrlon': '(4.0)', 'urcrnrlat': '(43.0)', 'resolution': '"""i"""', 'projection': '"""tmerc"""', 'lat_0': '(39.5)', 'lon_0': '(1)'}), "(llcrnrlon=-0.5, llcrnrlat=39.8, urcrnrlon=4.0, urcrnrlat=43.0,\n    resolution='i', projection='tmerc', lat_0=39.5, lon_0=1)\n", (169, 293), False, 'from mpl_toolkits.basemap import Basemap\n'), ((656, 669), 'matplotlib.pyplot.figure', 'plt.figure', (['(0)'], {}), '(0)\n', (666, 669), True, 'import matplotlib.pyplot as plt\n'), ((820, 833), 'matplotlib.pyplot.figure', 'plt.figure', (['(1)'], {}), '(1)\n', (830, 833), True, 'import matplotlib.pyplot as plt\n'), ((1076, 1089), 'matplotlib.pyplot.figure', 'plt.figure', (['(2)'], {}), '(2)\n', (1086, 1089), True, 'import matplotlib.pyplot as plt\n'), ((1430, 1443), 'matplotlib.pyplot.figure', 'plt.figure', (['(3)'], {}), '(3)\n', (1440, 1443), True, 'import matplotlib.pyplot as plt\n'), ((1731, 1741), 'matplotlib.pyplot.show', 'plt.show', ([], {}), '()\n', (1739, 1741), True, 'import matplotlib.pyplot as plt\n'), ((764, 772), 'numpy.array', 'array', (['x'], {}), '(x)\n', (769, 772), False, 'from numpy import array\n'), ((774, 782), 'numpy.array', 'array', (['y'], {}), '(y)\n', (779, 782), False, 'from numpy import array\n'), ((928, 936), 'numpy.array', 'array', (['x'], {}), '(x)\n', (933, 936), False, 'from numpy import array\n'), ((938, 946), 'numpy.array', 'array', (['y'], {}), '(y)\n', (943, 946), False, 'from numpy import array\n'), ((1184, 1192), 'numpy.array', 'array', (['x'], {}), '(x)\n', (1189, 1192), False, 'from numpy import array\n'), ((1194, 1202), 'numpy.array', 'array', (['y'], {}), '(y)\n', (1199, 1202), False, 'from numpy import array\n'), ((1538, 1546), 'numpy.array', 'array', (['x'], {}), '(x)\n', (1543, 1546), False, 'from numpy import array\n'), ((1548, 1556), 'numpy.array', 'array', (['y'], {}), '(y)\n', (1553, 1556), False, 'from numpy import array\n'), ((1247, 1263), 'matplotlib.colors.LogNorm', 'colors.LogNorm', ([], {}), '()\n', (1261, 1263), True, 'import matplotlib.colors as colors\n'), ((1562, 1570), 'numpy.array', 'array', (['c'], {}), '(c)\n', (1567, 1570), False, 'from numpy import array\n')]