!pip3 -q install git+http://github.com/SebMilardo/pychoropleth
from pychoropleth import choropleth, create_grid, add_cell_id, bounds_to_polygon
import pandas as pd
import numpy as np
import random
# create some random data
random.seed(27)
size = (10000,)
lon = np.random.normal(loc=15.11, scale=0.01, size=size)
lat = np.random.normal(loc=37.095, scale=0.1, size=size)
data = np.random.uniform(low=0, high=100, size=size)
df = pd.DataFrame(zip(lat,lon,data), columns=["latitude","longitude","data"])
bounds = bounds_to_polygon([15.0, 37.0,15.12, 37.11])
choropleth(df, grid_size=200, vmax=5, cmap="plasma", bounds=bounds, latitude="latitude",
longitude="longitude", tiles='cartodb_positron', column="data", crs=None, figsize=[10,10])
create_grid(df, grid_size=1000)
latitude | longitude | data | geometry | |
---|---|---|---|---|
cell_id | ||||
(0, 15) | 1 | 1 | 1 | POLYGON ((15.07514757880569 36.86284762884605,... |
(0, 18) | 1 | 1 | 1 | POLYGON ((15.07517407795653 36.88989145904608,... |
(0, 19) | 1 | 1 | 1 | POLYGON ((15.07518291886726 36.89890604169442,... |
(0, 24) | 2 | 2 | 2 | POLYGON ((15.07522718245621 36.94397874924348,... |
(0, 25) | 2 | 2 | 2 | POLYGON ((15.07523604699382 36.95299324960619,... |
... | ... | ... | ... | ... |
(6, 46) | 1 | 1 | 1 | POLYGON ((15.14298293170501 37.14223234470549,... |
(6, 51) | 1 | 1 | 1 | POLYGON ((15.14306785801639 37.18730309746841,... |
(6, 52) | 1 | 1 | 1 | POLYGON ((15.1430848659688 37.19631720676224, ... |
(6, 54) | 1 | 1 | 1 | POLYGON ((15.14311890459198 37.21434538408163,... |
(6, 58) | 1 | 1 | 1 | POLYGON ((15.14318707281081 37.25040157361436,... |
366 rows × 4 columns
a,b, = add_cell_id(df,10)
b
latitude | longitude | data | geometry | cell_id | |
---|---|---|---|---|---|
0 | 37.026004 | 15.095236 | 7.825212 | POINT (15.09523638316216 37.02600398150317) | (177, 3310) |
1 | 37.072862 | 15.127318 | 66.173434 | POINT (15.12731811121879 37.07286169126254) | (461, 3830) |
2 | 37.041645 | 15.125100 | 61.445199 | POINT (15.12510007143286 37.04164518165946) | (442, 3483) |
3 | 37.043505 | 15.111884 | 5.569417 | POINT (15.11188445414189 37.04350543862972) | (325, 3504) |
4 | 36.955362 | 15.107136 | 23.307228 | POINT (15.1071356126598 36.95536196068289) | (283, 2526) |
... | ... | ... | ... | ... | ... |
9995 | 37.106100 | 15.101078 | 19.076205 | POINT (15.10107755432147 37.10610026710734) | (228, 4198) |
9996 | 37.215616 | 15.094158 | 24.962796 | POINT (15.09415782743207 37.21561592522335) | (165, 5413) |
9997 | 37.278912 | 15.106320 | 50.637496 | POINT (15.10631993048477 37.2789118646031) | (272, 6115) |
9998 | 37.177729 | 15.106438 | 4.966513 | POINT (15.10643803659985 37.17772885943006) | (275, 4993) |
9999 | 37.012311 | 15.133427 | 69.098989 | POINT (15.13342737029825 37.01231068449707) | (517, 3158) |
10000 rows × 5 columns