Natural Language Processing with Python

Chapter 4.8

 colors = 'rgbcmyk' # red, green, blue, cyan, magenta, yellow, black

 def bar_chart(categories, words, counts):
"Plot a bar chart showing counts for each word by category"
import pylab ind = pylab.arange(len(words))
width = 0.1*1 / (len(categories) + 1)*10
bar_groups = []
for c in range(len(categories)):
bars = pylab.bar(ind+c*width, counts[categories[c]], width,
color=colors[c % len(colors)])
bar_groups.append(bars)
pylab.xticks(ind+width, words)
pylab.legend([b[0] for b in bar_groups], categories, loc='upper left')
pylab.ylabel('Frequency')
pylab.title('Frequency of Six Modal Verbs by Genre')
pylab.show() def test_bar_char():
genres = ['news', 'religion', 'hobbies', 'government', 'adventure']
modals = ['can', 'could', 'may', 'might', 'must', 'will']
cfdist = nltk.ConditionalFreqDist(
(genre, word)
for genre in genres
for word in nltk.corpus.brown.words(categories=genre)
if word in modals)
counts = {}
for genre in genres:
counts[genre] = [cfdist[genre][word] for word in modals]
bar_chart(genres, modals, counts)

修改了width,结果为:

Bar Chart of Frequency of modals in different sections of the Brown Corpus的更多相关文章

  1. Relative-Frequency|frequency|pie chart |bar chart

    2.2Organizing Qualitative Data The number of times a particular distinct value occurs is called its ...

  2. Highcharts - Bar Chart & Column Chart

    1. 条形图(Bar Chart)需要的数据格式类型如下: ["Luke Skywalker", "Darth Vader", "Yoda" ...

  3. Matplotlib之Bar Chart

    Matplotlib之Bar Chart: import numpy as np import matplotlib.pyplot as plt data = [[300, 200, 250, 150 ...

  4. bubble chart|Matrix Scatter|Overlay Scatter|Scatterplots|drop-line|box plot|Stem-and-leaf plot|Histogram|Bar chart|Pareto chart|Pie chart|doughnut chart|

    应用统计学 对类别数据要分类处理: Bar chart复式条形图便于对比: Pareto chart:对类别变量依据频数高低排列: Pie chart:饼图用于一个样本,可以区分类别数据 doughn ...

  5. 转 HighCharts笔记之: Bar Chart

    最近需要做一些Web图标,研究了几个开源的第三方工具后,最后决定使用HighCharts开发: Highcharts 是一个用纯JavaScript编写的一个图表库, 能够很简单便捷的在web网站或是 ...

  6. matplotlib 柱状图 Bar Chart 样例及参数

    def bar_chart_generator():     l = [1,2,3,4,5]     h = [20, 14, 38, 27, 9]     w = [0.1, 0.2, 0.3, 0 ...

  7. Bar Chart _Study

    ---恢复内容开始--- 以“3D BarChart”为例. 1.Select a theme.(选择一个主题模板) 2.Set up categories and groups.(设置类型和组) 3 ...

  8. plot bar chart using python

    Example import matplotlib.pyplot as plt import plotly.plotly as py # Learn about API authentication ...

  9. Matplotlib学习---用matplotlib画柱形图,堆积柱形图,横向柱形图(bar chart)

    这里利用Nathan Yau所著的<鲜活的数据:数据可视化指南>一书中的数据,学习画图. 数据地址:http://datasets.flowingdata.com/hot-dog-cont ...

随机推荐

  1. 由浅到深理解java反射

    1.基础概念 class类: 1.1java是面向对象的,但是在java中存在两种东西不是面向对象的 一种是普通的数据类型,这也是封装数据类存在的原因. 二种是静态静态成员. 1.2所以我们首先要理解 ...

  2. Video Cards

    Video Cards time limit per test 1 second memory limit per test 256 megabytes input standard input ou ...

  3. 异步加载AsyncTask

    private void huodeshuju() {        new AsyncTask<String, Void, String>() {            @Overrid ...

  4. Android中Edittext的属性

    //此为转载别人的,挺不错的 1.EditText输入的文字为密码形式的设置 (1)通过.xml里设置: 把该EditText设为:android:password="true"  ...

  5. 留言本,keyCode

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  6. POJ3468--A Simple Problem with Integers--线段树/树状数组 改段求段

    题目描述 You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. One type ...

  7. CodeForces 687A NP-Hard Problem(二分图判定)

    这本来一个挺简单的题呢,结果让我给想复杂了,二分图就是把图分成了两部分,然后不同颜色各一边,肯定是满足题目中说的边和点的条件的,真是犯二了.. 代码如下: #include<iostream&g ...

  8. js 基础笔记三

    词法结构: 1:区分大小写 2:特殊字符的区分,unicode转义 3:注释, //  ;  /* */ ; 4 : 标识字符和保留字 数据类型: 1原始类型 数字,字符串,布尔值.特殊的原始值(nu ...

  9. IDL 计算TVDI

    介绍请看:http://blog.sina.com.cn/s/blog_764b1e9d0100wdrr.html 源码: IDL 源码PRO TVDI,NDVI,LST,NBINS,RES RES ...

  10. struts2 严重: Error filterStart 原因

    当然你也可以用最新的struts2.3,把相应的包拷贝到工作区lib里 使用struts2.3.1所需的JAR包commons-fileupload-1.2.2.jarcommons-logging- ...