Skip to content

Commit

Permalink
Hotfix/issue 150 (#151)
Browse files Browse the repository at this point in the history
* Fix #150

* Replaces mcp module for extract_hex_colors_from_cmap()

* Remove fig title params
  • Loading branch information
alephcero authored May 31, 2024
1 parent ab94f80 commit a011d01
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 22 deletions.
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ seaborn
IPython
matplotlib-scalebar
numba
mycolorpy
streamlit
streamlit_folium
Pillow
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

setuptools.setup(
name='urbantrips',
version='0.2.4',
version='0.2.5',
author="Felipe Gonzalez & Sebastian Anapolsky",
author_email="",
description="A library to process public transit smart card data.",
Expand All @@ -31,7 +31,6 @@
'libpysal==4.8.0',
'mapclassify==2.6.1',
'matplotlib-scalebar==0.8.1',
'mycolorpy==1.5.1',
'notebook==7.0.4',
'numba==0.58.0',
'numpy==1.25.2',
Expand Down
19 changes: 16 additions & 3 deletions urbantrips/dashboard/pages/1_Datos Generales.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,31 @@
import mapclassify
import plotly.express as px
import matplotlib.pyplot as plt
from matplotlib import colors as mcolors
import seaborn as sns
import contextily as cx
from mycolorpy import colorlist as mcp
import os

import numpy as np
import yaml
import sqlite3
from shapely import wkt
from folium import Figure
from shapely.geometry import LineString


def extract_hex_colors_from_cmap(cmap, n=5):
# Choose a colormap
cmap = plt.get_cmap(cmap)

# Extract colors from the colormap
colors = cmap(np.linspace(0, 1, n))

# Convert the colors to hex format
hex_colors = [mcolors.rgb2hex(color) for color in colors]

return hex_colors


def create_linestring(df,
lat_o='lat_o',
lon_o='lon_o',
Expand Down Expand Up @@ -187,7 +200,7 @@ def crear_mapa_folium(df_agg,

line_w = 0.5

colors = mcp.gen_color(cmap=cmap, n=k_jenks)
colors = extract_hex_colors_from_cmap(cmap=cmap, n=k_jenks)

n = 0
for i in bins_labels:
Expand Down
10 changes: 3 additions & 7 deletions urbantrips/dashboard/pages/2_Indicadores de oferta.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import matplotlib.pyplot as plt
import seaborn as sns
import contextily as cx
from mycolorpy import colorlist as mcp
import os
from PIL import UnidentifiedImageError
from requests.exceptions import ConnectionError as r_ConnectionError
Expand Down Expand Up @@ -353,17 +352,14 @@ def plot_lineas(lineas, id_linea, nombre_linea, day_type, n_sections, rango):
)

try:
prov = cx.providers.Stamen.TonerLite
cx.add_basemap(ax1, crs=gdf_d0.crs.to_string(),
source=prov, attribution_size=7)
cx.add_basemap(ax2, crs=gdf_d1.crs.to_string(),
source=prov, attribution_size=7)
except (UnidentifiedImageError, ValueError):
prov = cx.providers.CartoDB.Positron
cx.add_basemap(ax1, crs=gdf_d0.crs.to_string(),
source=prov, attribution_size=7)
cx.add_basemap(ax2, crs=gdf_d1.crs.to_string(),
source=prov, attribution_size=7)
except (UnidentifiedImageError, ValueError):
cx.add_basemap(ax1, crs=gdf_d0.crs.to_string(), attribution_size=7)
cx.add_basemap(ax2, crs=gdf_d1.crs.to_string(), attribution_size=7)
except (r_ConnectionError):
pass

Expand Down
27 changes: 18 additions & 9 deletions urbantrips/viz/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
from pathlib import Path
from matplotlib import colors as mcolors
from matplotlib.text import Text
from mycolorpy import colorlist as mcp
from requests.exceptions import ConnectionError as r_ConnectionError
from pandas.io.sql import DatabaseError

Expand Down Expand Up @@ -544,14 +543,13 @@ def viz_etapas_x_tramo_recorrido(df,
shrink=0.05, edgecolor='Orange'),
)

prov = cx.providers.Stamen.TonerLite
prov = cx.providers.CartoDB.Positron
try:
cx.add_basemap(ax1, crs=gdf_d0.crs.to_string(), source=prov)
cx.add_basemap(ax2, crs=gdf_d1.crs.to_string(), source=prov)
except (UnidentifiedImageError, ValueError):
prov = cx.providers.CartoDB.Positron
cx.add_basemap(ax1, crs=gdf_d0.crs.to_string(), source=prov)
cx.add_basemap(ax2, crs=gdf_d1.crs.to_string(), source=prov)
cx.add_basemap(ax1, crs=gdf_d0.crs.to_string())
cx.add_basemap(ax2, crs=gdf_d1.crs.to_string())
except (r_ConnectionError):
pass

Expand Down Expand Up @@ -2219,7 +2217,7 @@ def crear_mapa_folium(df_agg,

line_w = 0.5

colors = mcp.gen_color(cmap=cmap, n=k_jenks)
colors = extract_hex_colors_from_cmap(cmap=cmap, n=k_jenks)

n = 0
for i in bins_labels:
Expand Down Expand Up @@ -2519,9 +2517,7 @@ def plot_basic_kpi(kpi_by_line_hr, standarize_supply_demand=False,
ax.set_xlabel("Hora")
ax.set_ylabel(ylabel_str)

f.suptitle(f"Indicadores de oferta y demanda estadarizados",
fontdict={'size': 18,
'weight': 'bold'})
f.suptitle(f"Indicadores de oferta y demanda estadarizados")

ax.set_title(f"{id_linea_str} id linea: {line_id} - Dia: {day_str}",
fontdict={"fontsize": 11})
Expand Down Expand Up @@ -2896,3 +2892,16 @@ def create_visualizations():

# plot basic kpi if exists
plot_basic_kpi_wrapper()


def extract_hex_colors_from_cmap(cmap, n=5):
# Choose a colormap
cmap = plt.get_cmap(cmap)

# Extract colors from the colormap
colors = cmap(np.linspace(0, 1, n))

# Convert the colors to hex format
hex_colors = [mcolors.rgb2hex(color) for color in colors]

return hex_colors

0 comments on commit a011d01

Please sign in to comment.