In [1]:
# encoding: utf-8
Para que o notebook IPython coloque as figuras geradas pela matplotlib inline:
In [2]:
%matplotlib inline
Bibliotecas
In [3]:
import pandas as pd
import geopandas as gpd
import matplotlib.pyplot as plt
In [4]:
focos = gpd.read_file(r"C:\Users\dougl\Desktop\programacao\focos_2016\focos_2016.shp")
In [5]:
focos["timestamp"] = pd.to_datetime(focos["DataHora"])
In [6]:
focos_tocantins = focos[focos.Estado == 'Tocantins']
In [7]:
focos_setembro = focos_tocantins[focos.timestamp.dt.month == 9]
In [8]:
focos_setembro.head(4)
Out[8]:
In [9]:
municipios = gpd.read_file(r"C:\Users\dougl\Desktop\programacao\focos_2016\municipios\municipios.shp")
In [10]:
#17 é o código IBGE para o Estado de Tocantins
municipios_to = municipios[municipios["GEOCODIGO"].str[0:2] == "17"]
In [11]:
focos_setembro.crs = {'init': 'epsg:4674'}
municipios_to.crs = {'init': 'epsg:4674'}
In [12]:
tocantins_dados = gpd.sjoin(focos_setembro, municipios_to, how="right", op='intersects')
In [13]:
tocantins_dados.head(4)
Out[13]:
In [14]:
municipios_tocantins = municipios_to.set_index('NOME')
In [15]:
focos_mes = tocantins_dados.groupby('NOME').Municipi.count()
In [16]:
focos_mes.index.name = "Municipios"
focos_mes.name = "focos"
focos_mes.head()
Out[16]:
In [17]:
focos_municipios = pd.concat([municipios_tocantins, focos_mes], axis=1)
focos_municipios.head()
Out[17]:
In [18]:
fig, ax = plt.subplots(1, figsize=(10, 15))
focos_municipios.plot(column='focos', ax=ax, cmap='Paired')
municipios_tocantins.plot(color='None', edgecolor='black', linewidth=1, ax=ax)
ax.axis('off')
vmin = focos_municipios['focos'].min()
vmax = focos_municipios['focos'].max()
# criando barra de cores
barra = plt.cm.ScalarMappable(cmap='Paired', norm=plt.Normalize(vmin=vmin, vmax=vmax))
barra._A = []
cbar = fig.colorbar(barra)
In [ ]: