Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 23218

Problem Adding Color bar to an animation plot in Python

$
0
0

I am having difficulty in adding a colorbar in a plot for animation in python.

Here's a part of my script:

test=(btemp/100)-273.15fig,[ax,cax] = plt.subplots(1,2, gridspec_kw={"width_ratios":[20,1]})plt.box(False)plt.figure(figsize=(5,4))ax = plt.axes(projection=ccrs.PlateCarree())ax.coastlines()ax.set_axis_off()cmap = 'twilight'norm = mpl.colors.Normalize(vmin=-50, vmax=50)cb1 = mpl.colorbar.ColorbarBase(cax, cmap=cmap,                            norm=norm,                            orientation='horizontal')def animate(time):xyz = test.isel(time=time).plot.contourf(norm=norm, origin='lower',                                   cmap=cmap, extend='both', add_colorbar=False)anim = animation.FuncAnimation(fig, animate,10,interval=400, repeat=False)HTML(anim.to_jshtml())

The output figure appears like this. I cant figure out why it is producing 3 images that are not properly aligned.

enter image description here

Can anyone help me figure this out? Thank you in advance for the help!


Viewing all articles
Browse latest Browse all 23218

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>