I am trying to use networks with Python. When I run this program, I get this error, is there anything missing?
(1) G.add_nodes_from ([2,3,4,5, 6,7,8,9,10]) # nx.draw_graphviz (g) #nx_write_dot (G, 'node.png') nx.draw (g)) Plt.savefig ("/ var / www / node.png" ) Traceback (most recent call final): File "GraphaPa", in Line 13, & lt; Module & gt; Nx.draw (g) file "/usr/lib/pymodules/python2.5/networkx/drawing/nx_pylab.py", line 124, Draw CF = pylab.gcf () file "/ usr / lib / pymodule / python2 "/usr/lib/pymodules/python2.5/matplotlib/pyplot.py", line 254, in figure ** kwargs) in the file ".5 / matplotlib / pyplot.py", line 276, GCF return figure () file " /usr/lib/pymodules/python2.5/matplotlib/backends/backend_tkagg.py ", in line 90, new_figure_manager window = Tk.Tk () file" /usr/lib/python2.5/lib-tk/Tkinfri.py ", Line 1650, __init__ self.tk = _tkinter.create (screen name, basename, classname, interactive, waroback, ugtik, sync, use) _tkinter.TclError: a display name and so on No $ DISPLAY environment variable
I get a different error:
#! / Usr / bin / env dragon import network xx as nx import matplotlib import matplotlib.pyplot matplotlib.use as matplotlib.pyplot plt ('ag') g = nx.graph () g.ad_node (1) g #nx from .ad_node_ ([2,3,4,5,6,7,8,9, 10]) Draw_Graphify (G) #nx_write_dot (G, 'Node.png') nx.draw (G) plt.savefig ("/ var / www / node.png")
/ usr / lib / pymodules /python2.5/matplotlib/__init__.py:835: User warning: this call has no effect with matplotlib.use () because the backend has already been selected; Matlotlib.use () should be imported * first * before pylab, matplotlib.pyplot, or matplotlib.backends. If the warning: warnings.warn (_use_error_msg) traceback (most recent call final): file "graph.py", line 15, & lt; Module & gt; Nx.draw (g) file "/usr/lib/python2.5/site-packages/networkx-1.2.dev-py2.5.egg/networkx/drawing/nx_pylab.py", Line 124, Draw CF = Yellow .gcf () file "/usr/lib/pymodules/python2.5/matplotlib/pyplot.py", line 276, gcf return figure () file "/usr/lib/pymodules/python2.5/matplotlib/pyplot. File ", line 254, figure ** in the keyword)" /usr/lib/pymodules/python2.5/matplotlib/backends/backend_tkagg.py ", line = 90, new_figure_manager window = Tk.Tk () file" / usr /lib/python2.5/lib-tk/Tkinter.py ", line 1650, __init__ in self.tk = _tkinter.create (screen name, basename, classname, interactive, violobex, utilityTack, sync, etc.) Yoga) _tkinter.TclError: No
/usr/lib/pymodules/python2.5/matplotlib/ __init__.py:835: User warning: this call has no effect with matplotlib.use () because the backend has already been selected; Matlotlib.use () should be imported * first * before pylab, matplotlib.pyplot, or matplotlib.backends. If the warning: warnings.warn (_use_error_msg) traceback (most recent call final): file "graph.py", line 15, & lt; Module & gt; Nx.draw (g) file "/usr/lib/python2.5/site-packages/networkx-1.2.dev-py2.5.egg/networkx/drawing/nx_pylab.py", Line 124, Draw CF = Yellow .gcf () file "/usr/lib/pymodules/python2.5/matplotlib/pyplot.py", line 276, gcf return figure () file "/usr/lib/pymodules/python2.5/matplotlib/pyplot. File ", line 254, figure ** in the keyword)" /usr/lib/pymodules/python2.5/matplotlib/backends/backend_tkagg.py ", line = 90, new_figure_manager window = Tk.Tk () file" / usr /lib/python2.5/lib-tk/Tkinter.py ", line 1650, __init__ in self.tk = _tkinter.create (screen name, basename, classname, interactive, violobex, utilityTack, sync, etc.) Yoga) _tkinter.TclError: no display name and no $ DISPLAY environment variable
main problem It is that Matplotlib (on your system) uses an X-backend by default, on one of my servers I had the same problem. The solution for me was to add the following code to the place before
import matplotlib # force to not use any Xwindows backend matplotlib Matplotlib.use ('Agg')
option etc. Area is to set your .matplotlibrc
No comments:
Post a Comment