Bar Chart of Frequency of modals in different sections of the Brown Corpus
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的更多相关文章
- Relative-Frequency|frequency|pie chart |bar chart
2.2Organizing Qualitative Data The number of times a particular distinct value occurs is called its ...
- Highcharts - Bar Chart & Column Chart
1. 条形图(Bar Chart)需要的数据格式类型如下: ["Luke Skywalker", "Darth Vader", "Yoda" ...
- Matplotlib之Bar Chart
Matplotlib之Bar Chart: import numpy as np import matplotlib.pyplot as plt data = [[300, 200, 250, 150 ...
- 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 ...
- 转 HighCharts笔记之: Bar Chart
最近需要做一些Web图标,研究了几个开源的第三方工具后,最后决定使用HighCharts开发: Highcharts 是一个用纯JavaScript编写的一个图表库, 能够很简单便捷的在web网站或是 ...
- 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 ...
- Bar Chart _Study
---恢复内容开始--- 以“3D BarChart”为例. 1.Select a theme.(选择一个主题模板) 2.Set up categories and groups.(设置类型和组) 3 ...
- plot bar chart using python
Example import matplotlib.pyplot as plt import plotly.plotly as py # Learn about API authentication ...
- Matplotlib学习---用matplotlib画柱形图,堆积柱形图,横向柱形图(bar chart)
这里利用Nathan Yau所著的<鲜活的数据:数据可视化指南>一书中的数据,学习画图. 数据地址:http://datasets.flowingdata.com/hot-dog-cont ...
随机推荐
- Toolbar Painter 工具条制作
工具条制作工具(ToolBarPainter2013.exe),专为程序猿设计,界面开发必备.当用VC编程制作工具条时,需要为工具栏上每一个button添加图标,是一件极其繁琐的事情,该工具可利用已有 ...
- Spring 与 mybatis整合 Error parsing Mapper XML. Cause: java.lang.NullPointerException
mapper配置文件中的namespace没有填:而且namespase的值应该填为:mapper的权限定名:否则还是会抛出异常 org.springframework.beans.factory.B ...
- 简单粗暴的“Debug模式”
在项目中,通常会遇到:调试程序和程序在线上运行时程序运行的参数不一样, 例如线上运行时程序是获取线上的机器的ip,而调试程序时,我们会指定一个ip进行调试. 又或者项目要与多个系统进行数据交换,调试的 ...
- 【kmp】 字符串最大周期
大侠住店 TimeLimit: 1 Second MemoryLimit: 32 Megabyte Totalsubmit: 116 Accepted: 64 Description 有一天晚上,一位 ...
- iframe子页面调用父页面javascript函数的方法
1.iframe子页面调用 父页面js函数 子页面调用父页面函数只需要写上window.parent就可以了.比如调用a()函数,就写成: window.parent.a(); 2.iframe父页面 ...
- SqlMapClient ,SqlExecutor 和SqlMapClientTemplate 的区别?
SqlMapClient SqlExecutor SqlMapClientTemplate
- JS-DOM操作应用高级(一)
表格应用--tBodies tHead tFoot rows cells <title>无标题文档</title> <script> window.onlo ...
- cocos2d-x 3.x 触摸事件
HelloWorldScene.h bool touchBegan(cocos2d::Touch*touch, cocos2d::Event*event);//触摸开始,返回bool类型 void t ...
- MaterialDrawer的使用
这是一个MaterialDesign风格的侧滑,在github上下载压缩包,按照github上的方式引入依赖,然后打开压缩包里面的例子程序,对照着APK看,即可知道怎么实现的(好像说了一堆废话..)
- iptables详解--转
出处:http://yijiu.blog.51cto.com/433846/1356254 iptables详解 基本概念: 1.防火墙工作在主机边缘:对于进出本网络或者本主机的数据报文,根据事先设定 ...