FIX: removing colorbar's axes also removes colorbar#31555
FIX: removing colorbar's axes also removes colorbar#31555rcomer wants to merge 1 commit intomatplotlib:mainfrom
Conversation
|
|
||
| # Override axes' remove method to properly remove the colorbar | ||
| self._ax_remove = self.ax._remove_method | ||
| self.ax._remove_method = functools.partial(_remove_cbar_axes, cbar=self) |
There was a problem hiding this comment.
I'm not sure I understand the interdependencies here:
Are you overriding ax._remove_method so that a user-called cbar.ax.remove() does the right thing? If so, why do we still need the old method around in self._ax_remove and call that in Colorbar.remove()? Shouldn't self.ax.remove() work there as well.
There was a problem hiding this comment.
Are you overriding
ax._remove_methodso that a user-calledcbar.ax.remove()does the right thing?
Yes
If so, why do we still need the old method around in
self._ax_removeand call that inColorbar.remove()? Shouldn'tself.ax.remove()work there as well.
Since self.ax.remove() now calls self.remove(), I think we would get a recursion error if self.remove() called self.ax.remove(). I admit I didn't actually try it though.
PR summary
Closes #31330
Replace the colorbar axes's remove method so it calls the colorbar's own remove method. The code from the issue now gives me a plot. I also thought about having the axes remove method raise an exception with a message to use the colorbar's method instead. However, I think either way we'd need to replace the method and it's no bigger change to support it than to make it raise.
This is an alternative solution to #31549, which was opened first.
AI Disclosure
None
PR checklist