Skip to content

Commit 7eda62a

Browse files
committed
Auto-update: Fri Nov 15 12:44:29 PST 2024
1 parent 5251907 commit 7eda62a

File tree

2 files changed

+21
-8
lines changed

2 files changed

+21
-8
lines changed

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
setuptools
2+
adblockparser
23
aiofiles
34
aiohttp
45
asyncpg
6+
better_profanity
57
elevation
8+
matplotlib
69
pydantic
710
python-dotenv
811
pyyaml
@@ -129,5 +132,3 @@ websockets
129132
whisper
130133
whisperplus
131134
youtube_dl
132-
better_profanity
133-
adblockparser

sijapi/routers/gis.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ async def generate_and_save_heatmap(
135135
:param output_path: The path to save the PNG file (optional)
136136
:return: The path where the PNG file was saved
137137
"""
138-
try:
138+
try:
139+
import matplotlib.pyplot as plt
140+
import numpy as np
141+
139142
start_date = await dt(start_date)
140143
if end_date:
141144
end_date = await dt(end_date)
@@ -149,14 +152,24 @@ async def generate_and_save_heatmap(
149152
lats = [loc.latitude for loc in locations]
150153
lons = [loc.longitude for loc in locations]
151154

152-
plt.figure(figsize=(10, 6))
153-
plt.hist2d(lons, lats, bins=50, cmap='hot')
154-
plt.colorbar(label='Count')
155+
plt.style.use('dark_background')
156+
fig, ax = plt.subplots(figsize=(10, 6))
157+
158+
# Create heatmap
159+
heatmap, xedges, yedges = np.histogram2d(lons, lats, bins=50)
160+
extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
161+
162+
# Plot with no axes or labels
163+
ax.imshow(heatmap.T, extent=extent, origin='lower', cmap='hot', interpolation='gaussian')
164+
ax.axis('off')
165+
166+
# Remove white border
167+
plt.gca().set_position([0, 0, 1, 1])
155168

156169
if output_path is None:
157170
output_path, relative_path = assemble_journal_path(end_date, filename="map", extension=".png", no_timestamp=True)
158171

159-
plt.savefig(output_path)
172+
plt.savefig(output_path, bbox_inches='tight', pad_inches=0, transparent=True)
160173
plt.close()
161174

162175
l.info(f"Heatmap saved as PNG: {output_path}")
@@ -167,7 +180,6 @@ async def generate_and_save_heatmap(
167180
raise
168181

169182

170-
171183
async def generate_map(start_date: datetime, end_date: datetime, max_points: int):
172184
locations = await fetch_locations(start_date, end_date)
173185
if not locations:

0 commit comments

Comments
 (0)