Numpy 使用Python/iPython时出现网络打印错误

Numpy 使用Python/iPython时出现网络打印错误,numpy,matplotlib,ipython,networkx,Numpy,Matplotlib,Ipython,Networkx,当我在IPython笔记本中尝试在OSX 10.8.2上使用networkx时,出现以下起始代码错误(AttributeError:非连续数组的不兼容形状) import networkx as nx g = nx.Graph() g.add_node(1) g.add_node(2) g.add_edge(1,2) # no error if this line is omitted nx.draw(g) 如果不将边添加到此图中,则看不到错误。Matplotlib、Numpy和Scipy都是

当我在IPython笔记本中尝试在OSX 10.8.2上使用networkx时,出现以下起始代码错误(AttributeError:非连续数组的不兼容形状)

import networkx as nx
g = nx.Graph()
g.add_node(1)
g.add_node(2)
g.add_edge(1,2) # no error if this line is omitted
nx.draw(g)
如果不将边添加到此图中,则看不到错误。Matplotlib、Numpy和Scipy都是按照建议安装的

以下是错误消息:


AttributeError回溯(最近一次调用)
在()
---->1 nx.图纸(g)
/usr/local/lib/python2.7/site-packages/networkx/drawing/nx_pylab.pyc in draw(G、pos、ax、hold、**kwds)
131 pylab.保持(h)
132尝试:
-->133绘制网络x(G,pos=pos,ax=ax,**kwds)
134轴设置轴关闭()
135 pylab.draw_if_interactive()
/usr/local/lib/python2.7/site-packages/networkx/drawing/nx_pylab.pyc in draw_networkx(G,pos,带_标签,**kwds)
265
266节点集合=绘制网络x节点(G、pos、**KWD)
-->267边缘收集=绘制网络x边缘(G,位置,**kwds)
268如果带有_标签:
269绘制网络X标签(G、pos、**KWD)
/usr/local/lib/python2.7/site-packages/networkx/drawing/nx_pylab.pyc in draw_networkx_edges(G,pos,edgelist,width,edge_color,style,alpha,edge_cmap,edge_vmin,edge_vmax,ax,箭头,标签,**kwds)
544边集合。设置边序(1)#边位于节点后面
545边缘集合。设置标签(标签)
-->546 ax.添加_集合(边缘_集合)
547
548#注意:mpl中有一个关于处理
/添加集合(self、collection、autolim)中的usr/local/lib/python2.7/site-packages/matplotlib/axes.pyc
1443如果自动限制:
1444 if集合路径和len(集合路径):
->1445 self.update_datalim(collection.get_datalim(self.transData))
1446
1447 collection.\u remove\u method=lambda h:self.collections.remove(h)
/get_datalim(self,transData)中的usr/local/lib/python2.7/site-packages/matplotlib/collections.pyc
165偏移量=偏移量填充(np.nan)
166#get#path(获取路径)collection(收集数据块)处理nan但不处理掩码数组
-->167.shape=(-1,2)#设为Nx2
168
169结果=mpath.get\u路径\u集合\u范围(
AttributeError:非连续数组的不兼容形状
---------------------------------------------------------------------------
AttributeError回溯(最近一次呼叫上次)
/显示中的usr/local/lib/python2.7/site-packages/IPython/zmq/pylab/backend_inline.pyc(关闭)
100次尝试:
101用于Gcf中的图形管理器。获取所有图形管理器()
-->102发送\u图(图\u manager.canvas.figure)
103最后:
104显示。_至_绘制=[]
/发送图中的usr/local/lib/python2.7/site-packages/IPython/zmq/pylab/backend_inline.pyc(图)
209     """
210 fmt=InlineBackend.instance().图\u格式
-->211数据=打印图(图,fmt)
212#打印#如果没有要绘制的内容,则图形将返回无:
213如果数据为无:
/打印图中的usr/local/lib/python2.7/site-packages/IPython/core/pylabtools.pyc(图,fmt)
102尝试:
103字节_io=BytesIO()
-->104图画布打印图(字节io,格式=fmt,bbox英寸=紧密)
105数据=字节\ io.getvalue()
106.最后:
/打印图中的usr/local/lib/python2.7/site-packages/matplotlib/backend_base.pyc(self、文件名、dpi、facecolor、edgecolor、方向、格式,**kwargs)
1981方向=方向,
1982干润=真,
->1983年**夸尔格)
1984渲染器=self.figure.\u缓存渲染器
1985 bbox_inches=self.figure.get_tightbox(渲染器)
/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in print_png(self、filename_或_obj、*args、**kwargs)
467
468 def print_png(self、filename_或_obj、*args、**kwargs):
-->469图CAVASAGG.图纸(自)
470 renderer=self.get_renderer()
471原始_dpi=renderer.dpi
/绘图中的usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc(self)
419
请尝试:
-->421自图绘制(自渲染器)
422最后:
423 renderragg.lock.release()
/绘图包装中的usr/local/lib/python2.7/site-packages/matplotlib/artist.pyc(艺术家、渲染器、*args、**kwargs)
53 def draw_包装(艺术家、渲染器、*args、**kwargs):
54之前(艺术家、渲染器)
--->55绘制(艺术家、渲染器、*args、**kwargs)
56后(艺术家、渲染器)
57
/绘图中的usr/local/lib/python2.7/site-packages/matplotlib/figure.pyc(self,渲染器)
896 dsu.sort(key=itemgetter(0))
897对于dsu中的zorder、a、func、args:
-->898 func(*args)
899
900.关闭_组(“图”)
/绘图包装中的usr/local/lib/python2.7/site-packages/matplotlib/artist.pyc(艺术家、渲染器、*args、**kwargs)
53 def draw_包装(艺术家、渲染器、*args、**kwargs):
54之前(艺术家、渲染器)
--->55绘制(艺术家、渲染器、*args、**kwargs)
56后(艺术家、渲染器)
57
/绘图中的usr/local/lib/python2.7/site-packages/matplotlib/axes.pyc(self、renderer、inframe)
1995
1996年,佐尔德在dsu获得a:
->1997年a.draw(渲染器)
1998
1999.close_组(“轴”)
/绘图包装中的usr/local/lib/python2.7/site-packages/matplotlib/artist.pyc(艺术家、渲染器、*args、**kwargs)
53 def draw_包装(艺术家、渲染器、*args、**kwargs):
54之前(艺术家、渲染器)
--->55绘制(艺术家、渲染器、*args、**kwargs)
56后(艺术家、渲染器)
57
/绘图中的usr/local/lib/python2.7/site-packages/matplotlib/collections.pyc(self,渲染器)
AttributeError                            Traceback (most recent call last)

<ipython-input-33-df7dfeff6452> in <module>()
----> 1 nx.draw(g)

/usr/local/lib/python2.7/site-packages/networkx/drawing/nx_pylab.pyc in draw(G, pos, ax, hold, **kwds)
    131         pylab.hold(h)
    132     try:
--> 133         draw_networkx(G,pos=pos,ax=ax,**kwds)
    134         ax.set_axis_off()
    135         pylab.draw_if_interactive()

/usr/local/lib/python2.7/site-packages/networkx/drawing/nx_pylab.pyc in draw_networkx(G, pos, with_labels, **kwds)
    265 
    266     node_collection=draw_networkx_nodes(G, pos, **kwds)
--> 267     edge_collection=draw_networkx_edges(G, pos, **kwds)
    268     if with_labels:
    269         draw_networkx_labels(G, pos, **kwds)

/usr/local/lib/python2.7/site-packages/networkx/drawing/nx_pylab.pyc in draw_networkx_edges(G, pos, edgelist, width, edge_color, style, alpha, edge_cmap, edge_vmin, edge_vmax, ax, arrows, label, **kwds)
    544     edge_collection.set_zorder(1) # edges go behind nodes
    545     edge_collection.set_label(label)
--> 546     ax.add_collection(edge_collection)
    547 
    548     # Note: there was a bug in mpl regarding the handling of alpha values for

/usr/local/lib/python2.7/site-packages/matplotlib/axes.pyc in add_collection(self, collection, autolim)
   1443         if autolim:
   1444             if collection._paths and len(collection._paths):
-> 1445                 self.update_datalim(collection.get_datalim(self.transData))
   1446 
   1447         collection._remove_method = lambda h: self.collections.remove(h)

/usr/local/lib/python2.7/site-packages/matplotlib/collections.pyc in get_datalim(self, transData)
    165             offsets = offsets.filled(np.nan)
    166             # get_path_collection_extents handles nan but not masked arrays
--> 167         offsets.shape = (-1, 2)                     # Make it Nx2
    168 
    169         result = mpath.get_path_collection_extents(

AttributeError: incompatible shape for a non-contiguous array

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/usr/local/lib/python2.7/site-packages/IPython/zmq/pylab/backend_inline.pyc in show(close)
    100     try:
    101         for figure_manager in Gcf.get_all_fig_managers():
--> 102             send_figure(figure_manager.canvas.figure)
    103     finally:
    104         show._to_draw = []

/usr/local/lib/python2.7/site-packages/IPython/zmq/pylab/backend_inline.pyc in send_figure(fig)
    209     """
    210     fmt = InlineBackend.instance().figure_format
--> 211     data = print_figure(fig, fmt)
    212     # print_figure will return None if there's nothing to draw:
    213     if data is None:

/usr/local/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in print_figure(fig, fmt)
    102     try:
    103         bytes_io = BytesIO()
--> 104         fig.canvas.print_figure(bytes_io, format=fmt, bbox_inches='tight')
    105         data = bytes_io.getvalue()
    106     finally:

/usr/local/lib/python2.7/site-packages/matplotlib/backend_bases.pyc in print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, **kwargs)
   1981                     orientation=orientation,
   1982                     dryrun=True,
-> 1983                     **kwargs)
   1984                 renderer = self.figure._cachedRenderer
   1985                 bbox_inches = self.figure.get_tightbbox(renderer)

/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in print_png(self, filename_or_obj, *args, **kwargs)
    467 
    468     def print_png(self, filename_or_obj, *args, **kwargs):
--> 469         FigureCanvasAgg.draw(self)
    470         renderer = self.get_renderer()
    471         original_dpi = renderer.dpi

/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_agg.pyc in draw(self)
    419 
    420         try:
--> 421             self.figure.draw(self.renderer)
    422         finally:
    423             RendererAgg.lock.release()

/usr/local/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     53     def draw_wrapper(artist, renderer, *args, **kwargs):
     54         before(artist, renderer)
---> 55         draw(artist, renderer, *args, **kwargs)
     56         after(artist, renderer)
     57 

/usr/local/lib/python2.7/site-packages/matplotlib/figure.pyc in draw(self, renderer)
    896         dsu.sort(key=itemgetter(0))
    897         for zorder, a, func, args in dsu:
--> 898             func(*args)
    899 
    900         renderer.close_group('figure')

/usr/local/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     53     def draw_wrapper(artist, renderer, *args, **kwargs):
     54         before(artist, renderer)
---> 55         draw(artist, renderer, *args, **kwargs)
     56         after(artist, renderer)
     57 

/usr/local/lib/python2.7/site-packages/matplotlib/axes.pyc in draw(self, renderer, inframe)
   1995 
   1996         for zorder, a in dsu:
-> 1997             a.draw(renderer)
   1998 
   1999         renderer.close_group('axes')

/usr/local/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
     53     def draw_wrapper(artist, renderer, *args, **kwargs):
     54         before(artist, renderer)
---> 55         draw(artist, renderer, *args, **kwargs)
     56         after(artist, renderer)
     57 

/usr/local/lib/python2.7/site-packages/matplotlib/collections.pyc in draw(self, renderer)
    227         self.update_scalarmappable()
    228 
--> 229         transform, transOffset, offsets, paths = self._prepare_points()
    230 
    231         gc = renderer.new_gc()

/usr/local/lib/python2.7/site-packages/matplotlib/collections.pyc in _prepare_points(self)
    203 
    204         offsets = np.asanyarray(offsets, np.float_)
--> 205         offsets.shape = (-1, 2)             # Make it Nx2
    206 
    207         if not transform.is_affine:

AttributeError: incompatible shape for a non-contiguous array