mathause / mplotutils

helper functions for cartopy and matplotlib
MIT License
18 stars 3 forks source link

also re-compute colorbar on resize event #105

Open mathause opened 6 months ago

mathause commented 6 months ago

If we create a figure and then resize it, the colorbar is no longer correct. We need to add f.canvas.mpl_connect('resize_event', func).

https://github.com/mathause/mplotutils/blob/e48e8d156990f269b786e0d7f29b3c8c3ac2f16f/mplotutils/_colorbar.py#L201

%matplotlib
import mplotutils as mpu
import matplotlib.pyplot as plt
f, axs = plt.subplots(2)
axs = axs.flatten()
h = axs[0].pcolormesh([[0]], [[1]], [[1]])
cbar = mpu.colorbar(h, axs[0], axs[1])

f.set_size_inches(f.get_size_inches() * [0.75, 1], forward=False)

However, there seems no easy way to test this.