I am trying to use the output from networkx.draw function, which is a collection (LineCollection), to use in matplotlib.animation that requires an array. I dont want to save my figure as png, because there will be a lot of them. I also dont want to display it but it is not crucial.
A simple code can be:
import networkx as nx
graph= nx.complete_graph(5) #a simple graph with five nodes
Drawing=nx.draw(graph)
this outputs a python collection:
<matplotlib.collections.LineCollection at 0xd47d9d0>
I want to create a list of those kind of Drawings:
artists=[]
artists.append(Drawing)
And further use those drawings in an animation:
import matplotlib
fig= plt.figure() #initial figure, which can be empty
anim=matplotlib.animation.ArtistAnimation(fig, artists,interval=50, repeat_delaty=1000)
However i get a TypeError as below:
TypeError: 'LineCollection' object is not iterable
So, I figured the "artists" list should be a list of images which should either be numpy arrays or a png image or something called PIL (which I am not familiar with), and I dont know how to convert a collection to one of those without saving the image as png or any other format.
Actually this is what i want to do: a dynamic animation, when I try to use im = plt.imshow(f(x, y))
with one of the drawings I have, it gives this error:
TypeError: Image data can not convert to float
I hope I was clear enough, this is my first time with animation and plotting tools. Does anyone have a solution?