<jupyter_start><jupyter_text>Heatmaps<jupyter_code>import os
os.environ['HTTP_PROXY']=""
os.environ['HTTPS_PROXY']=""<jupyter_output><empty_output><jupyter_text>Heatmaps con Folium<jupyter_code>import pandas as pd

file=r"https://minsait-geospatial.s3.eu-west-3.amazonaws.com/data/Visualization/taxi_test.csv"
df_taxi = pd.read_csv(file)
df_taxi=df_taxi.sample(frac=0.01)
df_taxi.head()
df_taxi.pickup_datetime = pd.to_datetime(df_taxi.pickup_datetime, format='%Y-%m-%d %H:%M:%S')
df_taxi['month'] = df_taxi.pickup_datetime.apply(lambda x: x.month)
df_taxi['week'] = df_taxi.pickup_datetime.apply(lambda x: x.week)
df_taxi['day'] = df_taxi.pickup_datetime.apply(lambda x: x.day)
df_taxi['hour'] = df_taxi.pickup_datetime.apply(lambda x: x.hour)
df_hour_list = []
for hour in df_taxi.hour.sort_values().unique():
    df_hour_list.append(df_taxi.loc[df_taxi.hour == hour, ['pickup_latitude', 'pickup_longitude', 'count']].groupby(['pickup_latitude', 'pickup_longitude']).sum().reset_index().values.tolist())
def generateBaseMap(default_location=[40.693943, -73.985880], default_zoom_start=12):
    base_map = folium.Map(location=default_location, control_scale=True, zoom_start=default_zoom_start)
    return base_map
import folium
from folium.plugins import HeatMap

base_map = generateBaseMap(default_zoom_start=11)
HeatMap(data=df_taxi[['pickup_latitude', 'pickup_longitude']].groupby(['pickup_latitude', 'pickup_longitude']).sum().reset_index().values.tolist(), radius=8, max_zoom=13).add_to(base_map)
base_map
from folium.plugins import HeatMapWithTime
base_map = generateBaseMap(default_zoom_start=11)
#base_map = folium.Map([47, 7.7], zoom_start=5, tiles='CartoDB positron')
HeatMapWithTime(df_hour_list, radius=10, auto_play=True, gradient={0.9: 'blue', 0.4: 'lime', 0.6: 'orange', 1: 'red'}, min_opacity=0.5, max_opacity=0.8, use_local_extrema=True).add_to(base_map)
base_map<jupyter_output><empty_output><jupyter_text>Heatmaps con SeabornTambién es posible utilizar el procedimiento de (Kernel density estimation) para visualizar una distribución bivariada. En seaborn, este tipo de diagrama se muestra con un diagrama de contorno y está disponible como un estilo en jointplot ():<jupyter_code>import seaborn as sns
sns.jointplot(x='pickup_longitude', y='pickup_latitude', data=df_taxi, kind="kde");<jupyter_output><empty_output><jupyter_text>También podemos dibujar un diagrama de densidad de núcleo bidimensional con la función kdeplot (). Esto le permite dibujar este tipo de diagrama en un eje matplotlib específico.<jupyter_code>import matplotlib.pyplot as plt
f, ax = plt.subplots(figsize=(6, 6))
sns.kdeplot(df_taxi.pickup_longitude, df_taxi.pickup_latitude, ax=ax)
sns.rugplot(df_taxi.pickup_longitude, color="g", ax=ax)
sns.rugplot(df_taxi.pickup_latitude, vertical=True, ax=ax);
f, ax = plt.subplots(figsize=(6, 6))
cmap = sns.cubehelix_palette(as_cmap=True, dark=0, light=1, reverse=True)
sns.kdeplot(df_taxi.pickup_longitude, df_taxi.pickup_latitude, cmap=cmap, n_levels=60, shade=True);<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13730655251893314, 'fraction_numerical': 0.018439249259137307, 'mean_word_length': 8.706070287539935, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '664282', 'license': 'MIT', 'n_tokens_mistral': 1222, 'n_tokens_neox': 1193, 'n_words': 197, 'path': 'notebooks/HeatMaps.ipynb', 'repo_name': 'minsait-geospatial/geo-binder', 'size': '3037'}