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. springmvc 关于controller的字符编码

    在使用springMVC框架构建web应用,客户端常会请求字符串.整型.json等格式的数据,通常使用@ResponseBody注解使 controller回应相应的数据而不是去渲染某个页面.如果请求 ...

  2. POJ1556 The Doors 叉积+最短路

    题目大意:求从(0,5)到(10,5)的最短距离,起点与终点之间有n堵墙,每个墙有2个门. 题目思路:判断两点间是否有墙(判断两点的连线是否与某一堵墙的线段相交),建立一个图,然后最短路求出就可以了. ...

  3. synchronized关键字以及实例锁 类锁

    Java语言的关键字,当它用来修饰一个方法或者一个代码块的时候,能够保证在同一时刻最多只有一个线程执行该段代码. 一.当两个并发线程访问同一个对象object中的这个synchronized(this ...

  4. CentOS安装VirtualBox增强工具

    安装过程中出现错误: Bulding the VirtualBox Guest Additions Kernel modules failedYour system does not seem to  ...

  5. JAVA动态代理详解

    1.什么是代理 代理模式是常用的Java 设计模式,它的特征是代理类与委托类有同样的接口,代理类主要负责为委托类预处理消息.过滤消息.把消息转发给委托类,以及事后处理消息等. 2.什么是动态代理 在程 ...

  6. 转:WebDriver(Selenium2) 判断页面是否刷新的方法

    public static boolean waitPageRefresh(WebElement trigger) { int refreshTime = 0; boolean isRefresh = ...

  7. ZooKeeper应用理论及其应用场景

    ZooKeeper Client APIZooKeeper Client Library提供了丰富直观的API供用户程序使用,下面是一些常用的API: ● create(path, data, fla ...

  8. 别说你不知道java中的包装类,wrapper type,以及容易在自动拆箱中出现的问题

    很多时候,会有人问你,你知道什么是包装类吗? 或者高端一点问你你知道,wrapper type,是什么吗? 然后你就懵逼了,学了java很多时候都不知道这是啥. 其实问你的人,可能只是想问你,java ...

  9. 求余区间的求和类问题 离线+线段树 HDU4228

    题目大意:给一个数组a,他的顺序是严格的单调增,然后有如下三个操作 ①加入一个val到a数组里面去,加入的位置就是a[i-1]<val<a[i+1] ②删除一个a[i]=val的值 ③查询 ...

  10. 转 Android开发者指南-Manifest.xml-<supports-screens

    <supports-screens> 版本:Android 3.2 语法: <supports-screensandroid:resizeable=["true" ...