I’m trying to plot an interpolated heatmap of RSSI (received signal strength indication) point values on a static map with Python and Seaborn.
The data is in a local InfluxDB but for the sake of this question, I exported them as CSV. The CSV file and the additionally used shape file are available here: https://cloud.gofferje.net/s/BT7bJaS7ybtP8zn
This is my code:
import requests as r
import io
import matplotlib.pyplot as plt
import pandas as pd
import geopandas as gpd
import seaborn as sns
import tilemapbase as tm
df=pd.read_csv('rangemap.csv')
gdf = gpd.GeoDataFrame(df,
geometry = gpd.points_from_xy(df['lon'], df['lat']),
crs = 'EPSG:4326')
gdf = gdf.to_crs("EPSG:3857")
vlk = gpd.read_file("Valkeakoski.shp")
vlk = vlk.to_crs("EPSG:3857")
tm.init(create=True)
extent = tm.extent_from_frame(vlk)
fig, ax = plt.subplots(figsize=(12,10),layout="constrained")
ax.xaxis.set_visible(False)
ax.yaxis.set_visible(False)
plotter = tm.Plotter(extent, tm.tiles.build_OSM(), width=1000)
plotter.plot(ax)
sns.kdeplot(data=gdf,x=gdf['geometry'].x,y=gdf['geometry'].y,fill=True,cmap='turbo',alpha=0.3,levels=20,weights=gdf['rssi'],cbar=True,ax=ax,zorder=3)
vlk.plot(color=(1,1,1,0),edgecolor="black",linewidth=0.5,ax=ax)
So far, I have achieved a plot which looks about right:
What is confusing me a bit are the values in the color bar. The RSSI values in the CSV file go from -55 to -145. What I would like to see in the color bar are the actual RSSI values. I assume what the color bar is showing are the results of the KDE math based on the RSSI as weights?
I also tried to use hue=gdf['rssi']
instead of weights=gdf['rssi']
but that doesn’t create a map at all, however, the color bar looks right…
How would I get an interpolated map of the RSSI values with the “right” color bar, i.e. the color bar showing the RSSI values?
6