pylab/networkx;更新后未显示任何节点标签 [英] pylab/networkx; no node labels displayed after update
问题描述
将matplotlib更新到当前版本后,在networkX中遇到节点标签问题:如果使用nx.draw(G)
命令,将得到一个图形,但未显示任何标签.但是让我们举个例子:
After I have updated matplotlib to the current version I encounter a problem with node labels in networkX: if I use the nx.draw(G)
command, I get a graph, but no labels are displayed. But let's speak with examples:
import networkx as nx
import matplotlib.pylab as plt
T=nx.Graph()
T.add_edge(0,1)
nx.draw(T)
plt.show()
这将返回有效图,但没有节点标签.即使我像
this returns a valid plot, but with no node labels. Even if I pass the labels directly like in
import networkx as nx
import matplotlib.pylab as plt
T=nx.Graph()
T.add_edge(0,1)
labs={}
labs[0]='cake'
labs[1]='cookie'
nx.draw(T,labels=labs)
plt.show()
仍然没有标签.我很确定它(尤其是上层)在更新之前已在昨天运行.那么matplotlib 1.3.x是否有变化(不记得我之前运行的确切版本)?当前版本是:
there are still no labels. I'm pretty sure it (especially the upper one) was working yesterday before the update. So was there a change from matplotlib 1.3.x (don't remember the exact one I was running previously)? The current versions are:
matplotlib (1.4.0) (had to downgrade the pyparsing to 1.5.7 after updating the matplotlib)
networkx (1.9)
python 2.7.6
Mac OS X 10.9.4
一点额外的东西:如果我用nx.draw(T, with_labels=True)
运行上面的代码,我会得到一个图(我的设置上有一个额外的窗口),当我关闭它时,会弹出一个TypeError: bad argument type for built-in operation
.如果我运行nx.draw(T, with_labels=False)
并不会发生,这非常令人困惑,因为我认为with_labels
参数采用布尔值(
Little Extra: if i run the upper code with nx.draw(T, with_labels=True)
I get a plot (extra window on my settings) and when I close it a TypeError: bad argument type for built-in operation
pops up. It does not happen if I run nx.draw(T, with_labels=False)
, which is very confusing, since I thought with_labels
argument takes a boolean (see here), which it (partially) does not....?
我在这里误会了什么吗?
Am I misunderstanding something here?
@tcaswell希望对您有所帮助!
@tcaswell hope that helps!
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/usr/local/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
57 def draw_wrapper(artist, renderer, *args, **kwargs):
58 before(artist, renderer)
---> 59 draw(artist, renderer, *args, **kwargs)
60 after(artist, renderer)
61
/usr/local/lib/python2.7/site-packages/matplotlib/figure.pyc in draw(self, renderer)
1077 dsu.sort(key=itemgetter(0))
1078 for zorder, a, func, args in dsu:
-> 1079 func(*args)
1080
1081 renderer.close_group('figure')
/usr/local/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
57 def draw_wrapper(artist, renderer, *args, **kwargs):
58 before(artist, renderer)
---> 59 draw(artist, renderer, *args, **kwargs)
60 after(artist, renderer)
61
/usr/local/lib/python2.7/site-packages/matplotlib/axes/_base.pyc in draw(self, renderer, inframe)
2090
2091 for zorder, a in dsu:
-> 2092 a.draw(renderer)
2093
2094 renderer.close_group('axes')
/usr/local/lib/python2.7/site-packages/matplotlib/artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
57 def draw_wrapper(artist, renderer, *args, **kwargs):
58 before(artist, renderer)
---> 59 draw(artist, renderer, *args, **kwargs)
60 after(artist, renderer)
61
/usr/local/lib/python2.7/site-packages/matplotlib/text.pyc in draw(self, renderer)
536 renderer.open_group('text', self.get_gid())
537
--> 538 bbox, info, descent = self._get_layout(renderer)
539 trans = self.get_transform()
540
/usr/local/lib/python2.7/site-packages/matplotlib/text.pyc in _get_layout(self, renderer)
309 tmp, lp_h, lp_bl = renderer.get_text_width_height_descent('lp',
310 self._fontproperties,
--> 311 ismath=False)
312 offsety = (lp_h - lp_bl) * self._linespacing
313
/usr/local/lib/python2.7/site-packages/matplotlib/backends/backend_macosx.pyc in get_text_width_height_descent(self, s, prop, ismath)
164 size = self.points_to_pixels(points)
165 width, height, descent = self.gc.get_text_width_height_descent(
--> 166 six.text_type(s), family, size, weight, style)
167 return width, height, 0.0*descent
168
TypeError: bad argument type for built-in operation
(我既不是数学家,也不是程序员,但愿意学习,所以请耐心等待!)
(I'm neither a mathematician nor a programmer, but willing to learn, so please be patient!)
推荐答案
This is hitting a known (but unresolved) bug in the OSX backend (#3470).
切换到基于Agg的后端之一应该通过避免它来解决"问题.
Switching to one of the Agg based backends should 'resolve' the problem by avoiding it.
更新
已经确定并合并了部分问题 https://github.com/matplotlib/matplotlib /pull/3564 .此修复程序应在mpl v1.4.1及更高版本中进行.
Part of the problem has been identified and merged https://github.com/matplotlib/matplotlib/pull/3564. This fix should be in mpl v1.4.1 and higher.
这篇关于pylab/networkx;更新后未显示任何节点标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!