After multiple scans and plots, heatmap becomes 3% smaller each scan (fixed)

This commit is contained in:
iamdoubz committed 2026-05-01 16:43:30 -05:00
1 parent 48300a5927
commit afbc6f77e9
1 file changed
+10 -5
+10 -5
View File
@@ -63,10 +63,12 @@ def render_heatmap(
if fig is None or ax is None:
fig, ax = plt.subplots(figsize=(10, 7))
fig.subplots_adjust(right=0.88) # permanent right margin for the colorbar
# Remove any colorbars left over from previous renders.
# Colorbars attach to the figure, not the axes, so ax.clear() doesn't touch them.
for ax_obj in fig.axes[1:]: # axes[0] is the main plot; everything else is a colorbar
# Remove any axes that aren't the main plot (stale colorbars, etc.).
# We then recreate a fixed-position colorbar axes below so matplotlib never
# steals space from ax — that is what caused ax to shrink on every redraw.
for ax_obj in fig.axes[1:]:
ax_obj.remove()
ax.clear()
@@ -115,14 +117,17 @@ def render_heatmap(
)
if show_colorbar:
cbar = fig.colorbar(img_heatmap, ax=ax, fraction=0.03, pad=0.02)
# Add a fixed-position axes for the colorbar. Using cax= instead of
# ax= means matplotlib draws into this dedicated axes without
# touching ax at all — no space is stolen, ax never shrinks.
cax = fig.add_axes([0.91, 0.15, 0.02, 0.70]) # [left, bottom, width, height]
cbar = fig.colorbar(img_heatmap, cax=cax)
cbar.set_label("Signal Strength (dBm)", fontsize=10)
cbar.ax.tick_params(labelsize=8)
cbar.ax.text(1.4, -90, "Poor", transform=cbar.ax.get_yaxis_transform(),
fontsize=7, color='gray', va='bottom')
cbar.ax.text(1.4, -30, "Excellent", transform=cbar.ax.get_yaxis_transform(),
fontsize=7, color='gray', va='top')
# Black swatch at the very bottom representing "no signal found"
cbar.ax.text(1.4, -95, "No signal", transform=cbar.ax.get_yaxis_transform(),
fontsize=7, color='black', va='top',
bbox=dict(facecolor='white', edgecolor='none', pad=1.5))