Problem with plt.savefig()

2,507 views
Skip to first unread message

Sergio Hernandez

unread,
Jun 11, 2010, 11:13:25 PM6/11/10
to networkx...@googlegroups.com
Hi everyone


I'm having this problem with pyplot and networkx (versions 0.36 and 0.99) and the problem is that whenever I want to do this

>>> import networx as nx
>>> import matplotlib.pyplot as plt
>>> G = nx.read_yaml("graph.yaml")
>>> nx.draw(G)
>>> plt.savefig("figure.png")

I get an empty picture, but if, instead I do

>>> plt.show()

there I can save the figure without any problem

what am I doing wrong? does anyone knows?


greetings

Sergio

Aric Hagberg

unread,
Jun 12, 2010, 11:09:43 AM6/12/10
to networkx...@googlegroups.com

That looks correct and works for me.
(though I am likely using different versions of
networkx and matplotlib than you).
e.g.

>>> import networkx as nx
>>> G=nx.path_graph(4)
>>> nx.draw(G)
>>> import matplotlib.pyplot as plt
>>> plt.savefig('figure.png')

produces an image of the path graph.

Does this work for other matplotlib plots?
e.g.

>>> plt.plot([1,2,3])
>>> plt.savefig('figure.png')

If not then there is some issue with matplotlib...

Aric

Reply all
Reply to author
Forward
0 new messages