Main Content

WordCloud

创建文字云图表,字袋型号,n-grams型号或LDA模型

Description

Text Analytics Toolbox™扩展了WordCloud(MATLAB®) 功能。它增加了直接从字万博1manbetx符串数组中创建单词云的支持,并从字袋模型,n-gram模型和LDA主题中创建单词云。如果you do not have Text Analytics Toolbox installed, then seeWordCloud

例子

WordCloud(str通过对文字进行象征化和预处理文本来创建单词云图表str, 和then displaying the words with sizes corresponding to the word frequency counts. This syntax supports English, Japanese, German, and Korean text.

例子

WordCloud(文件从出现的单词中创建一个单词云图表文件

例子

WordCloud(从字袋或n-grams模型中创建一个单词云图表

例子

WordCloud(tbl,,,,WordVar,,,,sizevar从表中创建一个单词云图表tbl。变量WordVarsizevar在表中分别指定单词和单词大小。

WordCloud(,,,,尺寸creates a word cloud chart from elements of带有单词大小由尺寸

WordCloud(Ccreates a word cloud chart from the elements of categorical arrayC使用frequency counts.

例子

WordCloud(ldaMdl,,,,topicidx用索引从主题中创建一个单词云图表topicidxof the LDA modelldaMdl

WordCloud(___,,,,名称,价值指定其他WordCloudChart使用一个或多个名称值对参数的属性。

WordCloud(父母,,,,___在图,面板或选项卡中创建单词云父母

厕所= WordCloud(___返回WordCloudChart目的。Use厕所创建云单词的属性。有关属性列表,请参见WordClodchart属性

Examples

全部收缩

提取文本sonnets.txt使用ExtractFileText和display the text of the first sonnet.

str= extractFileText(“十四行诗”);extractBefore(str,"II"
ans =“我们希望增加的最公平生物的威廉·莎士比亚(William Shakespeare I)的十四行诗,因此美丽的玫瑰可能永远不会死,但是随着时间的流逝,他的柔和的继承人可能会承受他的记忆:但是你与你的明亮的眼睛相关了,将您的光的火焰喂食自然的燃料,使饥荒在饥荒中,你的敌人,你的甜蜜自我太残酷了:你现在那种艺术现在是世界的新鲜装饰品,只有在宽阔的春天,在内部的春天,你自己的芽最埋葬的内容,嫩的churl mak浪费在niggarding中:可惜的世界,否则这个glut是在坟墓和你身上吃掉这个世界的。”

显示文字云十四行诗的一个词。

图WordCloud(str);

图包含一个类型WordCloud的对象。

加载示例数据。文件sonnetsPreprocessed.txt包含莎士比亚十四行诗的预处理版本。该文件包含每行十四行诗,单词被一个空间隔开。提取文本sonnetsPreprocessed.txt,将文本分成新线字符的文档,然后将文档归为文档。

文件名=“ Sonnetspreprocessed.txt”;str = extractfiletext(filename);textdata = split(str,newline);documents = tokenizedDocument(textData);

使用单词云可视化文档。

图WordCloud(文档);

图包含一个类型WordCloud的对象。

加载示例数据。文件sonnetsPreprocessed.txt包含莎士比亚十四行诗的预处理版本。该文件包含每行十四行诗,单词被一个空间隔开。提取文本sonnetsPreprocessed.txt,将文本分成新线字符的文档,然后将文档归为文档。

文件名=“ Sonnetspreprocessed.txt”;str = extractfiletext(filename);textdata = split(str,newline);documents = tokenizedDocument(textData);

Create a bag-of-words model using小词

包= bagOfWords(documents)
Bag =带有属性的Bagofword:计数:[154x3092 double]词汇:[“ fairest”“最”“生物”“ desire” ...] numwords:3092 numdocuments:154

使用Word Cloud可视化字袋模型。

图WordCloud(袋);

图包含一个类型WordCloud的对象。

加载示例数据sonnetsTable。桌子tbl在变量中包含单词列表Word, 和the corresponding frequency counts in the variableCount

加载sonnetsTable头(TBL)
ans=8×2桌单词计数___________ _____ {'''tis'} 1 {'''''''} 1 {''''''} 2 {''gainst'} 1 {''thou'} 1 {'so'} 1

使用表数据绘制表数据WordCloud。Specify the words and corresponding word sizes to be theWordCountvariables respectively.

图WordCloud(tbl,'单词',,,,'数数');title(“十四行诗云”

图包含一个类型WordCloud的对象。这chart of type wordcloud has title Sonnets Word Cloud.

要在此示例中重现结果,请集RNG'default'

RNG('default'

加载示例数据。文件sonnetsPreprocessed.txt包含莎士比亚十四行诗的预处理版本。该文件包含每行十四行诗,单词被一个空间隔开。提取文本sonnetsPreprocessed.txt,将文本分成新线字符的文档,然后将文档归为文档。

文件名=“ Sonnetspreprocessed.txt”;str = extractfiletext(filename);textdata = split(str,newline);documents = tokenizedDocument(textData);

Create a bag-of-words model using小词

包= bagOfWords(documents)
Bag =带有属性的Bagofword:计数:[154x3092 double]词汇:[“ fairest”“最”“生物”“ desire” ...] numwords:3092 numdocuments:154

Fit an LDA model with 20 topics. To suppress verbose output, set'Verbose'至0。

mdl = fitlda(袋子,20,'Verbose',,,,0)
mdl = ldaModel with properties: NumTopics: 20 WordConcentration: 1 TopicConcentration: 5 CorpusTopicProbabilities: [0.0500 0.0500 0.0500 0.0500 0.0500 ... ] DocumentTopicProbabilities: [154x20 double] TopicWordProbabilities: [3092x20 double] Vocabulary: ["fairest" "creatures" ... ] TopicOrder: 'initial-fit-probability' FitInfo: [1x1 struct]

使用Word Clouds可视化前四个主题。

数字为了topicidx= 1:4 subplot(2,2,topicIdx) wordcloud(mdl,topicIdx); title("Topic: "+ topicIdx)结尾

图包含类型WordCloud的对象。类型WordCloud的图表具有标题主题:1。WordCloud类型图表具有标题主题:2。Type WordCloud图表具有标题主题:3。类型WordCloud图表具有标题主题:4。

输入参数

全部收缩

输入文本,,,,specified as a string array, character vector, or cell array of character vectors.

对于字符串输入,WordCloudWordCloudCounts功能使用英语,日语,德语和韩国令牌化,删除单词范围和单词归一化。

Example:["an example of a short document";"a second short document"]

Data Types:细绳|char|细胞

输入文档,指定为象征性文档大批。

输入表,,,,with columns specifying the words and word sizes. Specify the words and the corresponding word sizes in the variables given byWordVarsizevar输入参数。

Data Types:桌子

单词数据的表变量,指定为字符串标量,字符向量,数字索引或逻辑向量。

Data Types:单身的|double|int8|int16|int32|int64|UINT8|uint16|UINT32|Uint64|逻辑|char|细绳

大小数据的表变量,指定为字符串标量,字符向量,数字索引或逻辑向量。

Data Types:单身的|double|int8|int16|int32|int64|UINT8|uint16|UINT32|Uint64|逻辑|char|细绳

输入单词,指定为字符串向量或字符向量的单元格数组。

Data Types:细绳|细胞

单词大小数据,,,,specified as a numeric vector.

Data Types:单身的|double|int8|int16|int32|int64|UINT8|uint16|UINT32|Uint64

输入分类数据,指定为分类数组。函数绘制了每个唯一元素的Cwith size corresponding to历史图(C)

Data Types:categorical

输入袋或n-grams型号,指定为小词对象或一个Bagofngrams目的。如果是一个Bagofngrams对象,然后该函数将每个n-gram视为一个单词。

输入LDA模型,指定为ldamodel目的。

LDA主题索引,,,,specified as a nonnegative integer.

父母specified as a figure, panel, or tab.

名称值参数

将可选的参数对name1 = value1,...,namen = valuen,,,,where姓名是参数名称和价值is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

在R2021a之前,请使用逗号分隔每个名称和值,并附上姓名用引号。

Example:“亮光色”,“蓝色”specifies the highlight color to be blue.

WordCloudChart这里列出的属性只是子集。有关完整列表,请参阅WordClodchart属性

显示的最大单词数,指定为非负整数。该软件显示maxdisplaywords最大的单词。

单词颜色,指定为RGB三重序,包含颜色名称的字符向量或n-by-3 matrix wheren是长度WordData。如果颜色是一个矩阵,然后每行对应于相应单词的RGB三重态WordData

RGB三重态和十六进制颜色代码对于指定自定义颜色很有用。

  • RGB三重态是一个三元素行矢量,其元素指定了颜色的红色,绿色和蓝色组件的强度。强度必须在范围内[0,1];例如,[0.4 0.6 0.7]

  • A hexadecimal color code is a character vector or a string scalar that starts with a hash symbol ()followed by three or six hexadecimal digits, which can range from0F。这些值不敏感。因此,颜色代码'#ff8800',,,,'#ff8800',,,,'#f80', 和'#f80'是等效的。

另外,您可以按名称指定一些常见的颜色。该表列出了命名的颜色选项,等效的RGB三重态和十六进制颜色代码。

颜色名称 Short Name RGB三胞胎 十六进制的颜色代码 外貌
'红色的' 'r' [1 0 0] '#ff0000'

Sample of the color red

'绿色' 'g' [0 1 0] '#00ff00'

Sample of the color green

'blue' 'b' [0 0 1] '#0000FF'

蓝色样品

'青色' 'C' [0 1 1] '#00FFFF'

颜色青色样品

'magenta' 'm' [1 0 1] '#FF00FF'

颜色洋红色样品

'黄色' 'y' [1 1 0] '#ffff00'

黄色样品

'黑色的' 'k' [0 0 0] '#000000'

颜色黑色样品

'白色的' 'W' [1 1 1] '#ffffff'

颜色样品白色

这是MATLAB在许多类型的图中使用的默认颜色的RGB三重态和十六进制颜色代码。

RGB三胞胎 十六进制的颜色代码 外貌
[0 0.4470 0.7410] '#0072BD'

Sample of RGB triplet [0 0.4470 0.7410], which appears as dark blue

[0.8500 0.3250 0.0980] '#D95319'

RGB三重态样品[0.8500 0.3250 0.0980],如深橙色

[0.9290 0.6940 0.1250] '#EDB120'

RGB三重态样品[0.9290 0.6940 0.1250],显示为深黄色

[0.4940 0.1840 0.5560] '#7E2F8E'

RGB三重态样品[0.4940 0.1840 0.5560]

[0.4660 0.6740 0.1880] '#77AC30'

RGB三重态样品[0.4660 0.6740 0.1880],该样本如中等绿色

[0.3010 0.7450 0.9330] '#4DBEEE'

Sample of RGB triplet [0.3010 0.7450 0.9330], which appears as light blue

[0.6350 0.0780 0.1840] '#a2142f'

Sample of RGB triplet [0.6350 0.0780 0.1840], which appears as dark red

Example:'blue'

Example:[0 0 1]

单词亮点颜色,,,,specified as an RGB triplet, or a character vector containing a color name. The software highlights the largest words with this color.

RGB三重态和十六进制颜色代码对于指定自定义颜色很有用。

  • RGB三重态是一个三元素行矢量,其元素指定了颜色的红色,绿色和蓝色组件的强度。强度必须在范围内[0,1];例如,[0.4 0.6 0.7]

  • A hexadecimal color code is a character vector or a string scalar that starts with a hash symbol ()followed by three or six hexadecimal digits, which can range from0F。这些值不敏感。因此,颜色代码'#ff8800',,,,'#ff8800',,,,'#f80', 和'#f80'是等效的。

另外,您可以按名称指定一些常见的颜色。该表列出了命名的颜色选项,等效的RGB三重态和十六进制颜色代码。

颜色名称 Short Name RGB三胞胎 十六进制的颜色代码 外貌
'红色的' 'r' [1 0 0] '#ff0000'

Sample of the color red

'绿色' 'g' [0 1 0] '#00ff00'

Sample of the color green

'blue' 'b' [0 0 1] '#0000FF'

蓝色样品

'青色' 'C' [0 1 1] '#00FFFF'

颜色青色样品

'magenta' 'm' [1 0 1] '#FF00FF'

颜色洋红色样品

'黄色' 'y' [1 1 0] '#ffff00'

黄色样品

'黑色的' 'k' [0 0 0] '#000000'

颜色黑色样品

'白色的' 'W' [1 1 1] '#ffffff'

颜色样品白色

这是MATLAB在许多类型的图中使用的默认颜色的RGB三重态和十六进制颜色代码。

RGB三胞胎 十六进制的颜色代码 外貌
[0 0.4470 0.7410] '#0072BD'

Sample of RGB triplet [0 0.4470 0.7410], which appears as dark blue

[0.8500 0.3250 0.0980] '#D95319'

RGB三重态样品[0.8500 0.3250 0.0980],如深橙色

[0.9290 0.6940 0.1250] '#EDB120'

RGB三重态样品[0.9290 0.6940 0.1250],显示为深黄色

[0.4940 0.1840 0.5560] '#7E2F8E'

RGB三重态样品[0.4940 0.1840 0.5560]

[0.4660 0.6740 0.1880] '#77AC30'

RGB三重态样品[0.4660 0.6740 0.1880],该样本如中等绿色

[0.3010 0.7450 0.9330] '#4DBEEE'

Sample of RGB triplet [0.3010 0.7450 0.9330], which appears as light blue

[0.6350 0.0780 0.1840] '#a2142f'

Sample of RGB triplet [0.6350 0.0780 0.1840], which appears as dark red

Example:'blue'

Example:[0 0 1]

单词云图的形状,指定为'椭圆形'或者'长方形'

Example:'长方形'

输出参数

全部收缩

WordCloudChart目的。您可以修改一个WordCloudChart创建后。有关更多信息,请参阅WordClodchart属性

更多关于

全部收缩

Language Considerations

对于字符串输入,WordCloudWordCloudCounts功能使用英语,日语,德语和韩国令牌化,删除单词范围和单词归一化。

F或者other languages, you might need to manually preprocess your text data and specify unique words and corresponding sizes inWordCloud

WordCloud,,,,input your data as a table or arrays containing the unique words and corresponding sizes.

版本历史记录

在R2017b中引入