Show More
@@ -237,14 +237,20 b' class Component(HasTraitlets):' | |||
|
237 | 237 | self.config = config |
|
238 | 238 | # We used to deepcopy, but for now we are trying to just save |
|
239 | 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 | 244 | # self.config = deepcopy(config) |
|
242 | 245 | else: |
|
243 | 246 | if self.parent is not None: |
|
244 | 247 | self.config = self.parent.config |
|
245 | 248 | # We used to deepcopy, but for now we are trying to just save |
|
246 | 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 | 254 | # self.config = deepcopy(self.parent.config) |
|
249 | 255 | |
|
250 | 256 | self.created = datetime.datetime.now() |
@@ -315,7 +321,10 b' class Component(HasTraitlets):' | |||
|
315 | 321 | else: |
|
316 | 322 | # print "Setting %s.%s from %s.%s=%r" % \ |
|
317 | 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 | 329 | @property |
|
321 | 330 | def children(self): |
@@ -25,7 +25,7 b' def print_wordfreq(freqs, n=10):' | |||
|
25 | 25 | print word, count |
|
26 | 26 | |
|
27 | 27 | |
|
28 |
def wordfreq_to_weightsize(worddict, minsize= |
|
|
28 | def wordfreq_to_weightsize(worddict, minsize=25, maxsize=50, minalpha=0.5, maxalpha=1.0): | |
|
29 | 29 | mincount = min(worddict.itervalues()) |
|
30 | 30 | maxcount = max(worddict.itervalues()) |
|
31 | 31 | weights = {} |
@@ -37,7 +37,7 b' def wordfreq_to_weightsize(worddict, minsize=10, maxsize=50, minalpha=0.4, maxal' | |||
|
37 | 37 | return weights |
|
38 | 38 | |
|
39 | 39 | |
|
40 |
def tagcloud(worddict, n=10, minsize= |
|
|
40 | def tagcloud(worddict, n=10, minsize=25, maxsize=50, minalpha=0.5, maxalpha=1.0): | |
|
41 | 41 | from matplotlib import pyplot as plt |
|
42 | 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 | 55 | items = zip(alphas, sizes, words) |
|
56 | 56 | items.sort(reverse=True) |
|
57 | 57 | for alpha, size, word in items[:n]: |
|
58 | xpos = random.normalvariate(0.5, 0.3) | |
|
59 | ypos = random.normalvariate(0.5, 0.3) | |
|
60 |
|
|
|
61 |
|
|
|
58 | # xpos = random.normalvariate(0.5, 0.3) | |
|
59 | # ypos = random.normalvariate(0.5, 0.3) | |
|
60 | xpos = random.uniform(0.0,1.0) | |
|
61 | ypos = random.uniform(0.0,1.0) | |
|
62 | 62 | ax.text(xpos, ypos, word.lower(), alpha=alpha, fontsize=size) |
|
63 | 63 | ax.autoscale_view() |
|
64 | 64 | return ax |
General Comments 0
You need to be logged in to leave comments.
Login now