@@ -135,7 +135,10 @@ async def generate_and_save_heatmap(
135
135
:param output_path: The path to save the PNG file (optional)
136
136
:return: The path where the PNG file was saved
137
137
"""
138
- try :
138
+ try :
139
+ import matplotlib .pyplot as plt
140
+ import numpy as np
141
+
139
142
start_date = await dt (start_date )
140
143
if end_date :
141
144
end_date = await dt (end_date )
@@ -149,14 +152,24 @@ async def generate_and_save_heatmap(
149
152
lats = [loc .latitude for loc in locations ]
150
153
lons = [loc .longitude for loc in locations ]
151
154
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 ])
155
168
156
169
if output_path is None :
157
170
output_path , relative_path = assemble_journal_path (end_date , filename = "map" , extension = ".png" , no_timestamp = True )
158
171
159
- plt .savefig (output_path )
172
+ plt .savefig (output_path , bbox_inches = 'tight' , pad_inches = 0 , transparent = True )
160
173
plt .close ()
161
174
162
175
l .info (f"Heatmap saved as PNG: { output_path } " )
@@ -167,7 +180,6 @@ async def generate_and_save_heatmap(
167
180
raise
168
181
169
182
170
-
171
183
async def generate_map (start_date : datetime , end_date : datetime , max_points : int ):
172
184
locations = await fetch_locations (start_date , end_date )
173
185
if not locations :
0 commit comments