Repository: wright-group/WrightTools

Issue:
interact2D:  colorbar axes frame gets thicker when plotted data is changed
If redrawing the colorbar, delete the old one before drawing a new one.


Discussion:
I'll have to see a demonstration, I have not seen such behavior
![figure_1](https://user-images.githubusercontent.com/2501846/44162093-df764f00-a084-11e8-9c93-53c782ae2d3e.png)


This is also probably the same issue, it is rescalling the colorbar when local is on

Resolving patch:
diff --git a/WrightTools/artists/_interact.py b/WrightTools/artists/_interact.py
--- a/WrightTools/artists/_interact.py
+++ b/WrightTools/artists/_interact.py
@@ -82,10 +82,14 @@ def get_clim(channel, current_state):
     return clim
 
 
-def gen_ticklabels(points):
+def gen_ticklabels(points, signed=None):
     step = np.nanmin(np.diff(points))
-    if step == 0:
-        ticklabels = ["NaN" for point in points]
+    if step == 0:  # zeros everywhere
+        ticklabels = ['' for i in range(11)]
+        if signed:
+            ticklabels[5] = '0'
+        else:
+            ticklabels[0] = '0'
         return ticklabels
     ordinal = np.log10(np.abs(step))
     ndigits = -int(np.floor(ordinal))
@@ -216,6 +220,9 @@ def interact2D(data, xaxis=0, yaxis=1, channel=0, local=False, verbose=True):
         verbose=False,
     )[0]
     clim = get_clim(channel, current_state)
+    ticklabels = gen_ticklabels(np.linspace(*clim, 11), channel.signed)
+    if clim[0] == clim[1]:
+        clim = [-1 if channel.signed else 0, 1]
     obj2D = ax0.pcolormesh(
         current_state.dat,
         cmap=cmap,
@@ -229,6 +236,8 @@ def interact2D(data, xaxis=0, yaxis=1, channel=0, local=False, verbose=True):
     colorbar = plot_colorbar(
         cax, cmap=cmap, label=channel.natural_name, ticks=np.linspace(clim[0], clim[1], 11)
     )
+    colorbar.set_ticklabels(ticklabels)
+    fig.canvas.draw_idle()
 
     def draw_sideplot_projections():
         arr = current_state.dat[channel.natural_name][:]
@@ -353,9 +362,10 @@ def update_local(index):
             print("normalization:", index)
         current_state.local = radio.value_selected[1:] == "local"
         clim = get_clim(channel, current_state)
-        colorbar = plot_colorbar(
-            cax, cmap=cmap, label=channel.natural_name, ticks=np.linspace(clim[0], clim[1], 11)
-        )
+        ticklabels = gen_ticklabels(np.linspace(*clim, 11), channel.signed)
+        colorbar.set_ticklabels(ticklabels)
+        if clim[0] == clim[1]:
+            clim = [-1 if channel.signed else 0, 1]
         obj2D.set_clim(*clim)
         fig.canvas.draw_idle()
 
@@ -378,11 +388,11 @@ def update(info):
                 )
             obj2D.set_array(current_state.dat[channel.natural_name][:].ravel())
             clim = get_clim(channel, current_state)
+            ticklabels = gen_ticklabels(np.linspace(*clim, 11), channel.signed)
+            if clim[0] == clim[1]:
+                clim = [-1 if channel.signed else 0, 1]
             obj2D.set_clim(*clim)
-            ticklabels = gen_ticklabels(np.linspace(*clim, 11))
-            colorbar = plot_colorbar(
-                cax, cmap=cmap, label=channel.natural_name, ticks=np.linspace(clim[0], clim[1], 11)
-            )
+            colorbar.set_ticklabels(ticklabels)
             sp_x.collections.clear()
             sp_y.collections.clear()
             draw_sideplot_projections()


Test patch:
diff --git a/tests/artists/test_interact2D.py b/tests/artists/test_interact2D.py
--- a/tests/artists/test_interact2D.py
+++ b/tests/artists/test_interact2D.py
@@ -65,10 +65,10 @@ def test_4D():
     )
     signal[:, :, :, tau < 0] = 0
     signal[:, :, :, tau == 0] *= 0.5
-    signal = np.abs(signal)
+    signal = np.imag(signal)
 
     data = wt.data.Data(name="data")
-    data.create_channel("signal", values=signal, signed=False)
+    data.create_channel("signal", values=signal, signed=True)
     data.create_variable("w1", values=w1[:, None, None, None], units="wn")
     data.create_variable("w2", values=w2[None, :, None, None], units="wn")
     data.create_variable("w3", values=w3[None, None, :, None], units="wn")