title: matplotlib colorbar update/remove destroys axes layout
body: <p>I have matplotlib embedded in a tkinter gui. With the seaborn heatmap function, I create a heatmap and a colorbar which works as I want it to when creating the first plot. However, if I plot again, this will not overwrite the colorbar but add another colorbar to my figure. I end up with to many colorbars this way.</p>
  
  <p>The figure I create for the plot contains two axes:</p>
  
  <pre><code>[&lt;matplotlib.axes._subplots.AxesSubplot object at 0x000001F36C8C3390&gt;, &lt;matplotlib.axes._subplots.AxesSubplot object at 0x000001F36D6ABF98&gt;]
  </code></pre>
  
  <p>the first one is the plot itself and the second the colorbar and looks like this:
  <a href="https://imgur.com/cQeIFb4.png" rel="nofollow noreferrer">plot 1</a></p>
  
  <p>If I plot again, the result is:
  <a href="https://imgur.com/fWvp9zx.png" rel="nofollow noreferrer">plot 2</a></p>
  
  <p>Simply deleting the colorbar with </p>
  
  <pre><code>self.fig.axes[1].remove()
  </code></pre>
  
  <p>before creating the next plot doesn't do the trick because it will just remove the colorbar but the layout of the plot keeps shrinking:</p>
  
  <p><a href="https://imgur.com/cQeIFb4.png" rel="nofollow noreferrer">plot 3</a>
  <a href="https://imgur.com/YG4yXEd.png" rel="nofollow noreferrer">plot 4</a></p>
  
  <p>Note that the figure size stays the same but the size of the plot keeps getting smaller when I plot again and the colorbar moves futher to the left while the entire right part of the plot stays white.</p>
  
  <p>As I create a tkinter gui, the ploting window is initialized when the program is first run.</p>
  
  <pre><code>self.fig = plt.figure.Figure( facecolor = "white", figsize = (7,4)) 
  
            self.ax = self.fig.subplots()
  
            self.x_data = x_data
            self.y_data = y_data
  </code></pre>
  
  <p>when somebody presses a plot button the plot is created</p>
  
  <pre><code>    def plot_on_plotframe(self):
          self.ax.cla()
  
          #executes required matplotlib layout
          self.plotlayout[self.plot_type]()
  
          print('plottype: {}'.format(self.plot_type))       
          #print('Plot xdata: {}'.format(self.x_data))
          self.canvas.draw()
  </code></pre>
  
  <p>I need to make different types of plot and the proper type is selected by plotlayout:</p>
  
  <pre><code>        self.ax = sns.heatmap(self.x_data, vmin=self.settings[2][0], vmax=self.settings[2][1], cmap='viridis', fmt=self.settings[0], annot=self.settings[1], linewidths=0.5, annot_kws={'size': 8}, ax = self.ax)
  
          self.ax.set_xticklabels(self.ax.get_xticklabels(), rotation=0)
          self.fig.tight_layout()
  
  </code></pre>
  
  <p>It would be fantastic if somebody could tell me why matplotlib messes with the layout even after I delete the old colorbar in the first place. I think this has something to do with the gridSpec but I don't get how I tell matplotlib to reset the layout properly. Also any other suggestions on how to resovle this?</p>
  
  <p>Thanks in advance</p>