Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to generate animated subplots using matplotlib?

I want to generate a figure with 4 animations in python. I tried using the form below, but when running the program it generates the error ValueError: not enough values ​​to unpack (expected 4, got 2). What could be wrong?

fig, (axF, axS, axH, axHamilt) = plt.subplots(2, 2)

graphF,=axF.plot([],[])
graphS,=axS.plot([],[])
graphH,=axH.plot([],[])
graphHamilt,=axHamilt.plot([],[])
axF.set_ylim(-1.5, 1.5)
axF.set_xlim(ri, rf)
axF.grid()
axS.set_ylim(-1.5, 1.5)
axS.set_xlim(ri, rf)
axS.grid()
axH.set_ylim(-1.5, 1.5)
axH.set_xlim(ri, rf)
axH.grid()
axHamilt.set_ylim(-1.5, 1.5)
axHamilt.set_xlim(ri, rf)
axHamilt.grid()
def animate(i):
  graphF.set_data(r,Sevol[i])
  graphS.set_data(r, Fevol[i])
  graphH.set_data(r, Hevol[i])
  graphHamilt.set_data(r, Hevol[i])
  return graphF, graphS, graphH, graphHamilt
ani = FuncAnimation(fig, animate, frames=N_plots, interval=100)

plt.show()

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Note the parentheses:

fig, ((axF, axS), (axH, axHamilt)) = plt.subplots(2, 2)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading