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. Objective-C对象模型及应用

    引言 简介 与Runtime交互 Runtime术语 消息 动态方法解析 消息转发 健壮的实例变量(Non Fragile ivars) Objective-C Associated Objects ...

  2. Linux下的编程实战【转】

    一篇比较不错的文章, 降到了 makefile make , gcc编译器,GDB调试器, Linux文件系统,Linux文件API,.C语言库函数(C库函数的文件操作实际上是独立于具体的操作系统平台 ...

  3. 修改config.php配置

    $data=array( "name"=>"222222", "tel"=>159131, "address" ...

  4. 转:webdriver驱动未在默认目录安装的firefox

    刚开始用webdriver的朋友一定会苦恼它时常不能启动firefox,很多时候是因为firefox安装在默认路径下.此时,我们有些常用方法,可以解决此问题. [1] System.setProper ...

  5. android 5.0

    google 2014开发大会发布了全新的设计语言Material Design,并计划将其应用到Android.Chrome OS和网页等平台上,而最新发布的Android L系统就采用了这种设计语 ...

  6. 利用Hierarchy Viewer优化布局

    好久没更新博客了,趁着清明来写点什么. 今天来讲下如何使用android中提供的工具优化我们的布局.首先我们写一个最简单的框架布局. <?xml version="1.0" ...

  7. angular实现select的ng-options4

    ng实现简单的select <div ng-controller="ngSelect"> <select ng-model="vm.selectVal& ...

  8. tomcat服务器设置用户名和密码

    conf/tomcat-user.xml <user username="admin" password="1234" roles="manag ...

  9. 盖房子(house)

    盖房子(house) 题目描述 FJ最近得到了面积为n*m的一大块土地,他想在这块土地上建造一所房子,这个房子必须膏形的.但是,这块土地并非十全十美,上面有很多不平坦的地方(也可以叫瑕疵).这些瑕疵十 ...

  10. ant调用shell命令(Ubuntu)

    ant中调用Makefile,使用shell中的make命令 <?xml version="1.0" encoding="utf-8" ?> < ...