I'm recently install igraph on my windows machine running iPython through the Anaconda distribution. I have been following the tutorial on the igraph website to try and become familiar with igraph, as I typically use NetworkX. However, I'm having trouble actually drawing my graph.
At first, I realized it might be because I didn't enable pylab inline
, and I was receiving the error: NameError: name 'plot' is not defined
.
But after I enabled that and tried to plot the graph again, I got the error: TypeError: There is no line property "layout"
I simply want to draw my network in iPython, and I'm not sure what I'm doing wrong.
import igraph
import cairo
g = igraph.Graph([(0,1), (0,2), (2,3), (3,4), (4,2), (2,5), (5,0), (6,3), (5,6)])
cairo.__path__
Out[4]: ['C:\\Users\\Curtis\\Anaconda\\lib\\site-packages\\cairo']
layout = g.layout_kamada_kawai()
plot(g, layout = layout)
---------------------------------------------------------------------------
NameError Traceback (most recent call last)
<ipython-input-6-df59bbbf0497> in <module>()
----> 1 plot(g, layout = layout)
NameError: name 'plot' is not defined
After enabling pylab inline:
pylab inline
Populating the interactive namespace from numpy and matplotlib
plot(g, layout = layout)

---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-8-df59bbbf0497> in <module>()
----> 1 plot(g, layout = layout)
C:\Users\Curtis\Anaconda\lib\site-packages\matplotlib\pyplot.pyc in plot(*args, **kwargs)
2985 ax.hold(hold)
2986 try:
-> 2987 ret = ax.plot(*args, **kwargs)
2988 draw_if_interactive()
2989 finally:
C:\Users\Curtis\Anaconda\lib\site-packages\matplotlib\axes.pyc in plot(self, *args, **kwargs)
4135 lines = []
4136
-> 4137 for line in self._get_lines(*args, **kwargs):
4138 self.add_line(line)
4139 lines.append(line)
C:\Users\Curtis\Anaconda\lib\site-packages\matplotlib\axes.pyc in _grab_next_args(self, *args, **kwargs)
315 return
316 if len(remaining) <= 3:
--> 317 for seg in self._plot_args(remaining, kwargs):
318 yield seg
319 return
C:\Users\Curtis\Anaconda\lib\site-packages\matplotlib\axes.pyc in _plot_args(self, tup, kwargs)
303 ncx, ncy = x.shape[1], y.shape[1]
304 for j in xrange(max(ncx, ncy)):
--> 305 seg = func(x[:, j % ncx], y[:, j % ncy], kw, kwargs)
306 ret.append(seg)
307 return ret
C:\Users\Curtis\Anaconda\lib\site-packages\matplotlib\axes.pyc in _makeline(self, x, y, kw, kwargs)
255 **kw
256 )
--> 257 self.set_lineprops(seg, **kwargs)
258 return seg
259
C:\Users\Curtis\Anaconda\lib\site-packages\matplotlib\axes.pyc in set_lineprops(self, line, **kwargs)
196 funcName = "set_%s" % key
197 if not hasattr(line, funcName):
--> 198 raise TypeError('There is no line property "%s"' % key)
199 func = getattr(line, funcName)
200 func(val)
TypeError: There is no line property "layout"
Your command
plot(g, layout = layout)
has the problem. In the first case there is no plot
. In the second case you have loaded all sorts of stuff from matplotlib
to the common namespace, and plot
refers to matplotlib.pyplot.plot
.
What you really want to call is the igraph.plot
. So, replace the line above by
igraph.plot(g, layout=layout)
to use the correct function.
Just a minimal example:
import igraph
g = igraph.Graph([(0,1), (0,2), (2,3), (3,4), (4,2), (2,5), (5,0), (6,3), (5,6)])
igraph.plot(g, target="/tmp/igraph_demo.png")
creates:
Note that this creates a file. If your plot
without the target="..."
and do not get anything on the screen, it is a configuration issue. The solution depends on your OS. ( igraph
uses cairo
for SVG plotting.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.