I am trying to animate a geopandas plot unsing FuncAnimation. Basically eu_private_map is a geopandas.geodataframe.GeoDataFrame and among other fields, it contains several columns with the values for parameter x in different EU states across 10 consecutive years. Each column are the values of x for one year.
from matplotlib.animation import FuncAnimation
from IPython.display import HTML
from mpl_toolkits.axes_grid1 import make_axes_locatable
fig = plt.figure()
ax1 = fig.add_subplot(1,1,1)
def animate(year):
ax1.clear()
my_map = eu_private_map.plot(ax=ax1, column=year, vmin=0, vmax=30, legend=False)
divider = make_axes_locatable(ax1)
cax = divider.append_axes("right", size="5%", pad=0.05)
plt.colorbar(my_map, cax=cax)
# the FuncAnimation function iterates through our animate function using the steps array
years = eu_private.columns.drop('country').tolist()
ani = FuncAnimation(fig, animate, years, interval=1000, blit=False)
HTML(ani.to_jshtml())
The colorbar is giving me a hard time. On the one hand, if I set legend = True, I do not like the fact that it does not have the same size (see figure) as the figure and it creates a weird effect (see figure). I tried this but I got an error: AttributeError: 'AxesSubplot' object has no attribute 'autoscale_None'. However I cannot spot the trouble in the code, any help to fix both issues at once? Thanks a lot