From afbc6f77e9d057ceb58d7d142ed4085fcd7f46b0 Mon Sep 17 00:00:00 2001 From: iamdoubz <> Date: Fri, 1 May 2026 16:43:30 -0500 Subject: [PATCH] After multiple scans and plots, heatmap becomes 3% smaller each scan (fixed) --- renderer.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/renderer.py b/renderer.py index 3997030..b575cdb 100644 --- a/renderer.py +++ b/renderer.py @@ -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))