अद्यतन करने के बाद प्रदर्शित कोई नोड लेबल नहीं है, मैंने वर्तमान संस्करण में matplotlib को अद्यतन करने के बाद मुझे नेटवर्कएक्स में नोड लेबल के साथ एक समस्या का सामना करना पड़ता है: यदि मैं nx.draw(G)
कमांड का उपयोग करता हूं, तो मुझे ग्राफ मिलता है, लेकिन कोई लेबल प्रदर्शित नहीं होता है। लेकिन चलिए उदाहरणों के साथ बात करते हैं:पिलैब/नेटवर्कएक्स;
import networkx as nx
import matplotlib.pylab as plt
T=nx.Graph()
T.add_edge(0,1)
nx.draw(T)
plt.show()
यह एक मान्य साजिश देता है, लेकिन बिना किसी नोड लेबल के। यहां तक कि अगर मैं सीधे
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 से कोई परिवर्तन था (मुझे याद नहीं आया कि मैं पहले क्या चल रहा था)? वर्तमान संस्करण हैं:
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
तर्क एक बूलियन (see here) लेता है, जो यह (आंशिक रूप से) नहीं करता है ....?
क्या मैं यहां कुछ गलत समझ रहा हूं?
संपादित करें: @tcaswell उम्मीद है कि मदद करता है!
---------------------------------------------------------------------------
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
(मैं न तो एक गणितज्ञ और न ही एक प्रोग्रामर, लेकिन जानने के लिए तैयार हूँ, इसलिए कृपया धैर्य रखें!)
'नेटवर्क आयात' नहीं होना चाहिए 'आयात नेटवर्क' होना चाहिए? – unutbu
मैक पर हानिकारक स्वत: सुधार फ़ंक्शन :(यह कोड में सही तरीका है, ब्राउज़र –
में बस ठीक किया गया था, मैं पुष्टि कर सकता हूं कि लेबल 1.4 के साथ दिखाई नहीं दे रहा है। – tacaswell