##// END OF EJS Templates
Work on examples and fixed a super subtle bug in Component....
bgranger -
Show More
@@ -237,14 +237,20 b' class Component(HasTraitlets):'
237 self.config = config
237 self.config = config
238 # We used to deepcopy, but for now we are trying to just save
238 # We used to deepcopy, but for now we are trying to just save
239 # by reference. This *could* have side effects as all components
239 # by reference. This *could* have side effects as all components
240 # will share config.
240 # will share config. In fact, I did find such a side effect in
241 # _config_changed below. If a config attribute value was a mutable type
242 # all instances of a component were getting the same copy, effectively
243 # making that a class attribute.
241 # self.config = deepcopy(config)
244 # self.config = deepcopy(config)
242 else:
245 else:
243 if self.parent is not None:
246 if self.parent is not None:
244 self.config = self.parent.config
247 self.config = self.parent.config
245 # We used to deepcopy, but for now we are trying to just save
248 # We used to deepcopy, but for now we are trying to just save
246 # by reference. This *could* have side effects as all components
249 # by reference. This *could* have side effects as all components
247 # will share config.
250 # will share config. In fact, I did find such a side effect in
251 # _config_changed below. If a config attribute value was a mutable type
252 # all instances of a component were getting the same copy, effectively
253 # making that a class attribute.
248 # self.config = deepcopy(self.parent.config)
254 # self.config = deepcopy(self.parent.config)
249
255
250 self.created = datetime.datetime.now()
256 self.created = datetime.datetime.now()
@@ -315,7 +321,10 b' class Component(HasTraitlets):'
315 else:
321 else:
316 # print "Setting %s.%s from %s.%s=%r" % \
322 # print "Setting %s.%s from %s.%s=%r" % \
317 # (self.__class__.__name__,k,sname,k,config_value)
323 # (self.__class__.__name__,k,sname,k,config_value)
318 setattr(self, k, config_value)
324 # We have to do a deepcopy here if we don't deepcopy the entire
325 # config object. If we don't, a mutable config_value will be
326 # shared by all instances, effectively making it a class attribute.
327 setattr(self, k, deepcopy(config_value))
319
328
320 @property
329 @property
321 def children(self):
330 def children(self):
@@ -25,7 +25,7 b' def print_wordfreq(freqs, n=10):'
25 print word, count
25 print word, count
26
26
27
27
28 def wordfreq_to_weightsize(worddict, minsize=10, maxsize=50, minalpha=0.4, maxalpha=1.0):
28 def wordfreq_to_weightsize(worddict, minsize=25, maxsize=50, minalpha=0.5, maxalpha=1.0):
29 mincount = min(worddict.itervalues())
29 mincount = min(worddict.itervalues())
30 maxcount = max(worddict.itervalues())
30 maxcount = max(worddict.itervalues())
31 weights = {}
31 weights = {}
@@ -37,7 +37,7 b' def wordfreq_to_weightsize(worddict, minsize=10, maxsize=50, minalpha=0.4, maxal'
37 return weights
37 return weights
38
38
39
39
40 def tagcloud(worddict, n=10, minsize=10, maxsize=50, minalpha=0.4, maxalpha=1.0):
40 def tagcloud(worddict, n=10, minsize=25, maxsize=50, minalpha=0.5, maxalpha=1.0):
41 from matplotlib import pyplot as plt
41 from matplotlib import pyplot as plt
42 import random
42 import random
43
43
@@ -55,10 +55,10 b' def tagcloud(worddict, n=10, minsize=10, maxsize=50, minalpha=0.4, maxalpha=1.0)'
55 items = zip(alphas, sizes, words)
55 items = zip(alphas, sizes, words)
56 items.sort(reverse=True)
56 items.sort(reverse=True)
57 for alpha, size, word in items[:n]:
57 for alpha, size, word in items[:n]:
58 xpos = random.normalvariate(0.5, 0.3)
58 # xpos = random.normalvariate(0.5, 0.3)
59 ypos = random.normalvariate(0.5, 0.3)
59 # ypos = random.normalvariate(0.5, 0.3)
60 # xpos = random.uniform(0.0,1.0)
60 xpos = random.uniform(0.0,1.0)
61 # ypos = random.uniform(0.0,1.0)
61 ypos = random.uniform(0.0,1.0)
62 ax.text(xpos, ypos, word.lower(), alpha=alpha, fontsize=size)
62 ax.text(xpos, ypos, word.lower(), alpha=alpha, fontsize=size)
63 ax.autoscale_view()
63 ax.autoscale_view()
64 return ax
64 return ax
General Comments 0
You need to be logged in to leave comments. Login now