Пример #1
0
def generate_vincent(corpus):
    punctuation = list(string.punctuation)
    count_all = Counter()
    stop = stopwords.words('english') + punctuation + [
        'rt', 'retweet', '…', 'th', 'via'
    ]
    corpus = str.lower(corpus)
    #   terms_stop = [term for term in preprocess(corpus) if term not in stop]
    #   terms_all = [term for term in preprocess(corpus)]
    #   terms_bigram = bigrams(terms_stop)

    # Count terms only (no hashtags, no mentions)
    terms_only = [
        term for term in preprocess(corpus)
        if term not in stop and not term.startswith(('#', '@'))
    ]
    # mind the ((double brackets))
    # startswith() takes a tuple (not a list) if
    # we pass a list of inputs
    count_all.update(terms_only)
    print(count_all.most_common(10))
    word_freq = count_all.most_common(20)
    labels, freq = zip(*word_freq)
    data = {'data': freq, 'x': labels}
    bar = vincent.Bar(data, iter_idx='x')
    bar.to_json('term_freq.json', html_out=True, html_path='chart.html')
Пример #2
0
def map_plot(file):
    # generate a new map
    folium_map = folium.Map(location=[43.6532, -79.3832],
                            zoom_start=13,
                            tiles="Stamen Terrain")

    for index, row in file.iterrows():

        #Defining marker colours.
        if int(row['actual_height']/3) <= int(row['ht_height']/3):
            color="#4daf4a"  

        else:
            color="#fc8d62" 
        # Create vincent chart and popup.
       
        data = [int(row["ht_height"]/3), int(row["actual_height"]/3),int(row["nearest_neigh"]/3),int(row["rand_forest"]/3)]
        ind = ['By-law Limit', 'Actual', 'Nearest Buildings', 'Random Forest']
        df = pd.DataFrame (data, index = ind)
        bar_chart = vincent.Bar(df,
                                width=350,
                                height=300)
        bar_chart.axis_titles (x='', y='Number of Floors')
        bar_chart.colors(brew='Set3')

        bar_chart.scales['x'].padding = 0.2

        bar_json = bar_chart.to_json()
        bar_dict = json.loads(bar_json)
        popup = folium.Popup(max_width=400)
        folium.Vega(bar_dict, height=350, width=400).add_to(popup)            
        folium.CircleMarker(location=(row["lat"],row["long"]),popup=popup, color=color, radius=5, fill=True ).add_to(folium_map)
    return folium_map
Пример #3
0
    def test_vega_popup(self):
        """Test vega popups."""

        self.map = folium.Map([45.60, -122.8])

        vega_templ = self.env.get_template('vega_marker.js')
        vega_parse = self.env.get_template('vega_parse.js')

        vis = vincent.Bar(width=675 - 75, height=350 - 50, no_data=True)
        data = json.loads(vis.to_json())

        self.map.simple_marker(location=[45.60, -122.8],
                               popup=(vis, 'vis.json'))

        marker = list(self.map._children.values())[-1]
        popup = list(marker._children.values())[-1]
        vega = list(popup._children.values())[-1]
        vega_str = vega_templ.render({
            'vega': vega.get_name(),
            'popup': popup.get_name(),
            'marker': marker.get_name(),
            'vega_json': json.dumps(data),
        })
        out = ''.join(self.map.get_root().render().split())
        assert ''.join(vega_parse.render().split()) in out
        assert (''.join(vega_str.split()))[:-1] in out
Пример #4
0
def create_map(df, col1):
    regions_geo = 'regions.geojson'
    df1 = df.groupby('Region').size()
    map_1 = folium.Map(location=[52.958, 0.7], zoom_start=7)
    map_1.choropleth(geo_path=regions_geo,
                     data=df1,
                     columns=['region_code', 'Size'],
                     key_on='properties.region_code',
                     fill_color='BuPu',
                     fill_opacity=0.7,
                     line_opacity=0.2,
                     legend_name='No. of people from region in census')

    for region in df['Region'].unique().tolist():
        df1 = df[df['Region'].str.contains(region)]
        bar = vincent.Bar(df1[col1].value_counts(), width=350, height=250)
        xtitle = col1 + "in: " + regions.get(region)
        bar.axis_titles(x=xtitle, y='')
        loc = coordinates.get(region)
        popup1 = folium.Popup(max_width=800, ).add_child(
            folium.Vega(bar, width=400, height=300))
        folium.RegularPolygonMarker(loc,
                                    fill_color='#43d9de',
                                    radius=12,
                                    popup=popup1).add_to(map_1)

    return map_1
def graphs(twitterJson):
    'Generates a graph with Vincent for use in Jscript'
    fname = twitterJson
    with open(fname, 'r') as f:
        count_all = Counter()
        count_bigrams = Counter()
        for line in f:
            try:
                tweet = json.loads(line)
                num_tweets += 1
            except ValueError:
                continue
            # Create a list with all the terms
            terms_all = [
                term for term in preprocess(tweet['text'])
                if term not in stop and not term.startswith(('#', '@'))
            ]
            # Update the counter
            count_all.update(terms_all)
            count_bigrams.update(bigrams(terms_all))
        word_freq = count_all.most_common(20)
        labels, freq = zip(*word_freq)
        data = {'data': freq, 'x': labels}
        bar = vincent.Bar(data, iter_idx='x')
        bar.to_json("term_freq.json")
Пример #6
0
def visualize_data():
    word_freq = count_terms_only.most_common(20)
    labels, freq = zip(*word_freq)
    data = {'data': freq, 'x': labels}
    bar = vincent.Bar(data, iter_idx='x')
    bar.to_json('term_freq.json')

    bar.to_json('term_freq.json', html_out=True, html_path='chart.html')
Пример #7
0
def processData():
    # twit.gatherTwitterData() uncomment this funciton to get a new set of tweets
    hashtags = Counter(getTags()).most_common(15)
    print hashtags
    labels, freq = zip(*hashtags)
    data = {'data':freq, 'x': labels}
    bar = vincent.Bar(data, iter_idx='x')
    bar.to_json('term_freq.json')
Пример #8
0
def graph_group_diff(id):
    group = Group.query.get_or_404(id)
    projects = group.projects.order_by(Project.score.desc()).all()
    scores = [project.score * score_multiplier for project in projects]
    index = [project.name for project in projects]
    data = {'scores': scores, 'index': index}
    bar_graph = vincent.Bar(data, iter_idx='index')
    bar_graph.scales['color'] = vincent.Scale(name='color',
                                              range=['#12897D'],
                                              type='ordinal')

    return jsonify({"status": "success", "data": bar_graph.grammar()})
Пример #9
0
    def test_vega_popup(self):
        '''Test vega popups'''

        vis = vincent.Bar()

        self.map.simple_marker(location=[45.60, -122.8], popup=(vis, 'vis.json'))
        popup_temp = self.env.get_template('vega_marker.js')
        vega = popup_temp.render({'mark': 'marker_1', 'div_id': 'vis',
                                  'width': 475, 'height': 250,
                                  'max_width': 900,
                                  'json_out': 'vis.json',
                                  'vega_id': '#vis'})
        assert self.map.template_vars['markers'][0][1] == vega
Пример #10
0
 def get_vincent_bar_chart(self, target_df, idx):
     total = target_df.loc[idx, :].sum()
     target_df = pd.DataFrame(
         {'count': target_df.loc[idx, :].sort_values(ascending=False)[:20]})
     vis = vincent.Bar(target_df['count'])
     vis.axes[0].properties = AxisProperties(labels=PropertySet(
         angle=ValueRef(value=45), align=ValueRef(value='left')))
     vis.axis_titles(x='',
                     y='Count of Main 20 Category / Total : {}'.format(
                         int(total)))
     vis.width = 300
     vis.height = 170
     # vis.padding['bottom'] = 90
     return vis.to_json()
Пример #11
0
    def test_vega_popup(self):
        """Test vega popups."""

        vis = vincent.Bar(width=675 - 75, height=350 - 50, no_data=True)

        self.map.simple_marker(location=[45.60, -122.8],
                               popup=(vis, 'vis.json'))
        popup_temp = self.env.get_template('vega_marker.js')
        vega = popup_temp.render({'mark': 'marker_1', 'div_id': 'vis',
                                  'width': 675, 'height': 350,
                                  'max_width': 900,
                                  'json_out': 'vis.json',
                                  'vega_id': '#vis'})
        assert self.map.template_vars['custom_markers'][0][2] == vega
def prepare_bar_chart_data(filter_method, filepath):
    """ Process tweets for visualation in a bar chart using D3.
    Uses Vincent to translate the data in Vega (usable by D3).

    Args:
        filter_method (function): filtering method to be used during feature
            extraction
        filepath (string): path to Tweet data from the Twitter API
    """
    word_freq = process_tweets(filter_method, filepath)[0].most_common(20)
    labels, freq = zip(*word_freq)
    data = {'data': freq, 'x': labels}
    bar = vincent.Bar(data, iter_idx='x')
    bar.to_json('web/term_freq.json')
Пример #13
0
def chart(request):
    domain = request.GET.get('domain')
    preview = request.GET.get('preview')
    leads = Leads()
    items = leads.get_leads(domain, preview)
    domain_count = Counter()
    domain_count.update([item['email'].split('@')[1] for item in items])
    domain_freq = domain_count.most_common(15)
    if len(domain_freq) == 0:
        return HttpResponse('No items to show', status=200)
    labels, freq = zip(*domain_freq)
    data = {'data': freq, 'x': labels}
    bar = vincent.Bar(data, iter_idx='x')
    items_to_show = json.dumps(bar.to_json())
    return render(request, 'chart.html', {'items_to_show': items_to_show})
def bar_plot(fname, count_all, at, term):
    word = term.capitalize()
    name = fname.split(".")[0].replace('Preprocess1',
                                       '').replace('_TR_',
                                                   '').replace('_TNR_', '')
    if at == "CommonCoOccurrences":
        word_freq = count_all[:5]
    elif at == "SpecificCoOccurrences":
        word_freq = count_all.most_common(6)
    else:
        word_freq = count_all.most_common(5)
    labels, freq = zip(*word_freq)
    data = {'data': freq, 'x': labels}
    bar = vincent.Bar(data, iter_idx='x')
    bar.to_json('%sBarFreq%s.json' % (name, at),
                html_out=True,
                html_path='%sBar%s%s.html' % (name, at, word))
Пример #15
0
def make_model(tweets, n, x_title, y_title):
    '''
    Makes bar chart of n most frequently written hashtags.

    Inputs:
        tweets: a list of tweets
        n: integer
        x_title: x axis title
        y_title: y axis title

	Returns: bar chart data
    '''
    top_hashtags = get_top_n_entities(tweets, ("hashtags", "text"), n)
    labels, freq = zip(*top_hashtags)
    data = {'data': freq, 'x': labels}
    bar = vis.Bar(data, iter_idx='x')
    bar.axis_titles(x=x_title, y=y_title)
    return bar
	def site_histogram(self, runmode):
		""" This method will produce a variety of histograms depending on the run modes.The supported run modes follow:
			all_selected - Histogram of the distribution of selected sites per gene """

		if "all_selected" in runmode:
			# Retrieving a list containing the selected sites for each PamlPair with evidence of selection (fdr < 0.05)
			selected_site_list = []

			for gene, pair in self.paml_pairs.items():
				if pair.fdr_value < 0.05:
					selected_site_list.append(len(pair.selected_aa))

			# Setting Bar plot list
			bar_list = []
			for i in range(max(selected_site_list) + 1):
				bar_list.append(selected_site_list.count(i))

			# Constructing plot
			site_hist = vincent.Bar(bar_list)
			site_hist.axis_titles(x="Number of selected sites (FDR < 0.05)", y="Frequency")
			site_hist.to_json("Site_histogram.json")
Пример #17
0
    def test_add_subtract(self):
        '''Test add and subtract on some subclasses'''

        bar = vincent.Bar()
        area = vincent.Area()

        area + ({
            'value': 'basis'
        }, 'marks', 0, 'properties', 'enter', 'interpolate')
        bar + ('red', 'marks', 0, 'properties', 'hover', 'fill', 'value')

        assert area.marks[0]['properties']['enter'].has_key('interpolate')
        assert bar.marks[0]['properties']['hover']['fill']['value'] == 'red'

        bar - ('domain', 'scales', 1)
        bar -= ('name', 'scales', 1)
        area - ('scale', 'axes', 0)
        area -= ('type', 'axes', 1)

        assert bar.scales[1] == {'nice': True, 'range': 'height'}
        assert area.axes == [{'type': 'x'}, {'scale': 'y'}]
Пример #18
0
def main2(fn):
    with open(fn + '.json', 'r') as f:
        count_all = Counter()
        search_word = ''

        for line in f:
            tweet = json.loads(line)
            tokens = preprocess(tweet['text'])

            #terms = terms_filter(tokens)
            terms = terms_single(terms_hash(tokens) + getHashtags(tweet))

            terms = contains_search_word(terms, search_word)
            count_all.update(terms)

    word_freq = count_all.most_common(10)
    print(word_freq)
    labels, freq = zip(*word_freq)
    data = {'data': freq, 'x': labels}
    bar = vincent.Bar(data, iter_idx='x')
    bar.to_json(fn + '.term_freq.json')
Пример #19
0
def graph_distribution():
    projects = Project.query.all()
    scores = [project.score for project in projects]
    bin_number = 30
    bin_width = 1 / bin_number
    x = []
    y = []
    curr_bin = 0
    for _ in range(bin_number):
        count = len([
            score for score in scores if score > curr_bin
            if score < curr_bin + bin_width
        ])
        x.append(curr_bin)
        y.append(count)
        curr_bin += bin_width

    data = {'x': x, 'y': y}
    bar = vincent.Bar(data, iter_idx='x')
    bar.scales['color'] = vincent.Scale(name='color',
                                        range=['#12897D'],
                                        type='ordinal')
    return bar.to_json()
Пример #20
0
def plot_term_freq(fname: str,
                   export_fname: str,
                   num_top_terms: int,
                   term_to_analyze_fname: str,
                   export_fname_for_trending_terms: str,
                   export_fname_for_non_trending_terms: str):

    terms_to_analyze = read_all_important_terms(term_to_analyze_fname)
    terms_date, count_all = analyze(fname, terms_to_analyze=terms_to_analyze)

    word_freq = count_all.most_common(num_top_terms)
    labels, freq = zip(*word_freq)
    data = {'data': freq, 'x': labels}
    bar = vincent.Bar(data, iter_idx='x')
    bar.to_json(export_fname)

    print("Term-Freq file exported at [%s]." % export_fname)

    export_terms(terms_date, count_all, labels,
                 export_fname_trending=export_fname_for_trending_terms,
                 export_fname_non_trending=export_fname_for_non_trending_terms)
    print("Terms with top trending terms are exported at [%s]" % export_fname_for_trending_terms)
    print("Terms without top trending terms are exported at [%s]" % export_fname_for_non_trending_terms)
Пример #21
0
    def add_marker(self, serie, longitude, latitude, arrondissement):
        liste_annee = []
        liste_valeur = []
        for annee in serie.index:
            liste_annee.append(annee)
        for valeur in serie.values:
            liste_valeur.append(valeur)

        scatter_points = {
            'x': liste_annee,
            'prix au m2': liste_valeur,
        }

        scatter_chart = vincent.Bar(scatter_points,
                                    iter_idx='x',
                                    width=300,
                                    height=200)
        scatter_chart.axis_titles(x='Année', y='Prix au m2')
        scatter_chart.legend(title=arrondissement)

        popup = folium.Popup()
        folium.Vega(scatter_chart, width=400, height=250).add_to(popup)
        folium.Marker([longitude, latitude], popup=popup).add_to(self.map)
Пример #22
0
            'mark predecessors')


df['parameters'] = df.apply(setParameters, axis=1)

# df.loc[df['mark_predecessors'] & df['undirected'], 'parameters'] = "BFS, undirected, mark predecessors"

## Bar graph, restricted to mark-pred+undirected
## x axis: dataset, y axis: MTEPS
## The following two subsetting operations are equivalent.
df_mteps = df[df['mark_predecessors'] & df['undirected']]  # except for BFS
df_mteps = df[df['parameters'] == "BFS, undirected, mark predecessors"]

## draw bar graph
# these next three appear to be equivalent
g_mteps = vincent.Bar(df_mteps, columns=['m_teps'],
                      key_on='dataset')  # key_on uses a DataFrame column
# for x-axis values
g_mteps = vincent.Bar(df_mteps.set_index('dataset'), columns=['m_teps'])
g_mteps = vincent.Bar(df_mteps.set_index('dataset')['m_teps'])
## Set plotting parameters for bar graph
g_mteps.axis_titles(x='Dataset', y='MTEPS')
# g_mteps.scales['y'].type = 'log'
g_mteps.colors(brew='Set3')
g_mteps.to_json('_g_mteps.json', html_out=True, html_path='g_mteps.html')

## Grouped bar graph
## DataFrame needs to be: rows: groups (dataset)
##                        cols: measurements (m_teps, but labeled by categories)
## Each row is a set of measurements grouped together (here, by dataset)
## Each column is an individual measurement (here, mteps)
##
Пример #23
0
def preprocess(s, lowercase=False):
    tokens = tokenize(s)
    if lowercase:
        tokens = [
            token if emoticon_re.search(token) else token.lower()
            for token in tokens
        ]
    return tokens


punctuation = list(string.punctuation)
stop = stopwords.words('english') + punctuation + ['rt', 'RT', 'via']

import string
fname = 'python.json'
with open(fname, 'r') as f:
    count_all = Counter()
    for line in f:
        tweet = json.loads(line)
        # Create a list with all the terms
        terms_stop = [
            term for term in preprocess(tweet['text']) if term not in stop
        ]
        # Update the counter
        count_all.update(terms_stop)

word_freq = count_all.most_common(20)
labels, freq = zip(*word_freq)
data = {'data': freq, 'x': labels}
bar = vincent.Bar(data, iter_idx='x')
bar.to_json('python.json')
Пример #24
0
import folium
import pandas as pd
import vincent

sbucks = pd.read_csv('starbucks_india.csv')

map_pune = folium.Map(location = [18.5204, 73.8567])

for index, row in sbucks.iterrows():
    lis = [row['Mon'], row['Tue'], row['Wed'], row['Thu'], row['Fri'], row['Sat'], row['Sun']]
    x = range(len(lis))
    bar = vincent.Bar(lis, width=440, height=200)
    bar.axis_titles(x='Day of week - ' +row['Name'], y='Foot fall')
    bar.to_json('vega.json')
    popup_ = folium.Popup(max_width=800).add_child(folium.Vega(bar, width=500, height=250))
    
    if sum(lis) > 2600:
        folium.Marker([row['Latitude'], row['Longitude']], popup=popup_,icon=folium.Icon(color='red', icon='star')).add_to(map_pune)
    else:
        folium.Marker([row['Latitude'], row['Longitude']], popup=popup_,icon=folium.Icon(color='green', icon='star-empty')).add_to(map_pune)

map_pune.save('starbucks_india_pune.html')
Пример #25
0
import json
import vincent

# <codecell>

# To allow vincent visualizations within an iPython notebook
vincent.core.initialize_notebook()

# <codecell>

#Iterable
list_data = [10, 20, 30, 20, 15, 30, 45]

# <codecell>

bar = vincent.Bar(list_data)
bar.axis_titles(x='Index', y='Value')
bar.height = 300
bar.width = 300
bar.display()

# <codecell>

line = vincent.Line(list_data)
line.axis_titles(x='Index', y='Value')
line.height = 300
line.width = 400
line.display()

# <codecell>
    file_.write(str(count_bigram.most_common(nElements)))

print "----------------------------"
print "Active: " + str(pr)
print "error: " + str(err)

print "generating geo data"
with open('WEB/geo_data.json', 'w') as fout:
    fout.write(json.dumps(geo_data, indent=4))

print "generating most common terms json"

word_freq = count_stop.most_common(nElements)
labels, freq = zip(*word_freq)
data = {'data': freq, 'x': labels}
bar = vincent.Bar(data, iter_idx='x', height=500, width=900)
bar.x_axis_properties(label_angle=-45, label_align="right")
bar.legend(title="Most frequent terms")
bar.to_json('WEB/freq_terms.json')

print "generating most common Langs"

word_freq = count_langs.most_common(nElements)
labels, freq = zip(*word_freq)
data = {'data': freq, 'x': labels}
bar = vincent.Bar(data, iter_idx='x', height=500, width=900)
bar.x_axis_properties(label_angle=-45, label_align="right")
bar.legend(title="Most frequent langs")
bar.to_json('WEB/freq_langs.json')

print "generating most common https json"
Пример #27
0
def generate_files(arg):

    term_file_name = "term_freq_" + arg + ".json"
    hash_file_name = "hash_freq_" + arg + ".json"
    chart_file_name = "time_chart_" + arg + ".json"
    sent_chart_file_name = "sent_time_chart_" + arg + ".json"
    geo_file_name = "geo_data_" + arg + ".json"
    geo_file_name_nsent = "geo_data_" + arg + ".json"
    geo_file_name_psent = "geo_data_" + arg + ".json"

    # file for map
    with open(geo_file_name, 'w') as fout:
        fout.write(json.dumps(geo_data, indent=4))

    def set_properties(bar, x_label='', y_label="Freq", padding=20):
        bar.height = 300
        bar.width = 600
        bar.axis_titles(x=x_label, y=y_label)

        ax = AxisProperties(labels=PropertySet(
            angle=ValueRef(value=70),
            dx=ValueRef(value=padding),
            font_size=ValueRef(value=11),
            font=ValueRef(value="Tahoma, Helvetica")),
                            title=PropertySet(dy=ValueRef(value=40)))
        bar.axes[0].properties = ax
        bar.scales['x'].padding = 0.2

    # file for hash frequency
    if count_hashs:
        word_freq = count_hashs.most_common(20)
        labels, freq = zip(*word_freq)
        data = {'data': freq, 'x': labels}
        bar = vincent.Bar(data, iter_idx='x')
        set_properties(bar, padding=25 + len(max(labels, key=len)))
        bar.to_json(hash_file_name)

    # file for term frequency
    if count_terms:
        word_freq = count_terms.most_common(20)
        labels, freq = zip(*word_freq)
        data = {'data': freq, 'x': labels}
        bar = vincent.Bar(data,
                          iter_idx='x',
                          padding=20 + len(max(labels, key=len)))
        set_properties(bar)
        bar.to_json(term_file_name)

    # file for time chart
    ones = [1] * len(timestamps)
    # the index of the series
    idx = pandas.DatetimeIndex(timestamps)
    # the actual series (at series of 1s for the moment)
    ITAvWAL = pandas.Series(ones, index=idx)
    # Resampling / bucketing
    per_hour = ITAvWAL.resample('30min').sum().fillna(0)
    time_chart = vincent.Line(per_hour)
    set_properties(time_chart, x_label='Time')
    time_chart.to_json(chart_file_name)

    # file for sentiment analysis
    idx = pandas.DatetimeIndex(timestamps)
    # the actual series (at series of 1s for the moment)
    ITAvWALp = pandas.Series(pos_ar, index=idx)
    ITAvWALn = pandas.Series(neg_ar, index=idx)
    ITAvWALnu = pandas.Series(neu_ar, index=idx)
    # Resampling / bucketing
    p_h = ITAvWALp.resample('12H').mean().fillna(0)
    p_n = ITAvWALn.resample('12H').mean().fillna(0)
    p_nu = ITAvWALnu.resample('12H').mean().fillna(0)
    xx = pandas.concat({
        "positove": p_h,
        "negative": p_n,
        "neutral": p_nu
    },
                       axis=1)
    time_chart = vincent.Line(xx)
    set_properties(time_chart, x_label='Time')
    time_chart.legend(title="catgeories")
    time_chart.to_json(sent_chart_file_name)
Пример #28
0
def make_graphic(word_freq, path='static/term_freq.json'):
    labels, freq = zip(*word_freq)
    data = {'vals': list(freq), 'index': list(labels)}
    bar = vincent.Bar(data, iter_idx='index')
    bar.axis_titles(y=u'Veces', x=u'Términos')
    bar.to_json(path)
Пример #29
0
price = pd.DataFrame({tic: data['Adj Close']
                      for tic, data in all_data.items()})

import collections
text = 'The sun did not shine It was too wet to play So we sat in the house All that cold cold wet day sat there with Sally we sat there we two And I said How I wish we had something to do Too wet to go out and too cold to play ball So we sat in the house We did nothing at all So all we could do was to Sit Sit Sit Sit And we did not like it Not one little bit And then something went BUMP How that bump made us jump We looked Then we saw him step in on the mat We looked And we saw him The Cat in the Hat And he said to us Why do you sit there like that I know it is wet And the sun is not sunny But we can have lots of good fun that is funny I know some good games we could play Said the cat I know some new tricks Said the Cat in the Hat A lot of good tricks I will show them to you Your mother Will not mind at all if I do Then Sally and I Did not know what to say Our mother was out of the house For the day But the fish said No No Make that cat go away Tell that Cat in the Hat you do NOT want to play He should not be here He should not be about He should not be here When your mother is out Now Now Have no fear Have no fear said the cat My tricks are not bad Said the Cat in the Hat Why we can have lots of good fun if you wish With a game that I call UP UP UP with a fish Put me down said the fish This is no fun at all Put me down said the fish I do NOT wish to fall Have no fear said the cat I will not let you fall I will hold you up high as I stand on a ball With a book on one hand And a cup on my hat But that is not ALL I can do said the cat Look at me Look at me now said the cat With a cup and a cake on the top of my hat I can hold up TWO books I can hold up the fish And a little toy ship And some milk on a dish And look I can hop up and down on the ball But that is not all Oh no That is not all Look at me Look at me Look at me NOW It is fun to have fun But you have to know how I can hold up the cup And the milk and the cake I can hold up these books And the fish on a rake I can hold the toy ship And a little toy man And look With my tail I can hold a red fan I can fan with the fan As I hop on the ball But that is not all Oh no That is not all That is what the cat said Then he fell on his head He came down with a bump from up there on the ball And Sally and I We saw ALL the things fall And our fish came down too He fell into a pot He said Do I like this Oh no I do not This is not a good game Said our fish as he lit No I do not like it Not one little bit Now look what you did Said the fish to the cat Now look at this house Look at this Look at that You sank our toy ship Sank it deep in the cake You shook up our house And you bent our new rake You SHOULD NOT be here when our mother is not You get out of this house Said the fish in the pot But I like it here Oh I like it a lot Said the Cat in the Hat To the fish in the pot I will NOT go away I do NOT wish to go And so said the Cat in the Hat So so so I will show you Another good game that I know And then he ran out And then fast as a fox The Cat in the Hat Came back in with a box A big red wood box It was shut with a hook Now look at this trick Said the cat Take a look Then he got up on top With a tip of his hat I call this game FUN IN A BOX Said the cat In this box are two things I will show to you now You will like these two things Said the cat with a bow I will pick up the hook You will see something new Two things And I call them Thing One and Thing Two These things will not bite you They want to have fun Then out of the box Came Thing Two and Thing One And they ran to us fast They said How do you do Would you like to shake hands With Thing One and Thing Two And Sally and I Did now know what to do So we had to shake hands With Thing One and Thing Two We shook their two hands But our fish said No No Those Things should not be In this house Make them go They should not be here When your mother is not Put them out Put them out Said the fish in the pot Have no fear little fish Said the Cat in the Hat These things are good Things And he gave them a pat They are tame Oh so tame They have come here to play They will give you some fun On this wet wet day Now here is a game that they like Said the cat They like to fly kites Said the Cat in the Hat No Not in the house Said the fish in the pot They should not fly kites In a house They should not Oh the things they will bump Oh the things they will hit Oh I do not like it Not one little bit Then Sally and I Saw them run down the hall We saw those two Things Bump their kites on the wall Bump Thump Thump Bump Down the wall in the hall Thing Two and Thing One They ran up They ran down On the string of one kit We saw Mothers new gown Her gown with the dots That are pink white and red Then we saw one kite bump On the head of her bed Then those Things ran about With big bumps jumps and kicks And with hops and big thumps And all kinds of bad tricks And I said I do NOT like the way that they play If Mother could see this Oh what would she say Then our fish said Look Look And our fish shook with fear Your mother is on her way home Do you hear Oh what will she do to us What will she say Oh she will not like it To find us this way So DO something Fast said the fish Do you hear I saw her Your mother Your mother is near So as fast as you can Think of something to do You will have to get rid of Thing One and Thing Two So as fast as I could I went after my net And I said With my net I can get them I bet I bet with my net I can get those Things yet Then I let down my net It came down the a PLOP And I had them At last Those two Things had to stop Then I said to the cat Now you do as I say You pack up those Things And you take them away Oh dear said the cat You did not like our game Oh dear What shame What a shame What a shame Then he shut up the Things In the box with the hook And the cat went away With a sad kind of look That is good said the fishHe has gone away Yes But your mother will come She will find this big mess And this mess is so big And so deep and so tall we can not pick it up There is no way at all And THEN Who was back in the house Why the cat Have no fear of this mess Said the Cat in the Hat I always pick up all my playthings And so I will show you another good trick that I know Then we saw him pick up all the things that were down He picked up the cake And the rake And the gown And the milk and the strings And the books and the dish And the fan and the cup And the ship and the fish And he put them away Then he said That is that And then he was gone with the tip of his hat Then our mother came in And said said to us two Did you have any fun Tell me What did you do And Sally and I did not know What to say Should we tell her The things that went on there that day She we tell her about it Now what SHOULD we do Well what would YOU do If you mother asked YOU'
counter = collections.Counter()
for w in text.split():
    counter[w] += 1
normalize = lambda x: int(x / (max(counter.values()) - min(counter.values())) * 90 + 10)
word_list = {k: normalize(v) for k, v in counter.items()}

# <codecell>

import vincent
vincent.core.initialize_notebook()
bar = vincent.Bar(multi_iter1['y1'])
bar.axis_titles(x='Index', y='Value')
bar.display()

# <codecell>

bar.to_json('bar.json', html_out=True, html_path='vincent_bar.html')

# <codecell>

line = vincent.Line(multi_iter1, iter_idx='index')
line.axis_titles(x='Index', y='Value')
line.legend(title='Categories')
line.display()

# <codecell>
Пример #30
0
# -*- coding: utf-8 -*-
'''
Builds a Vega grammar specification from vincent.Bar(), then plots
the output to the ipython notebook
'''

import vincent
import vincent.ipynb

vis = vincent.Bar()
vis.tabular_data((('A', 28), ('B', 55), ('C', 43), ('D', 91), ('E', 81),
                  ('F', 53), ('G', 19), ('H', 87), ('I', 52)))
vincent.ipynb.init_d3()
vincent.ipynb.init_vg()
vincent.ipynb.display_vega(vis)