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(
creates a word cloud chart from the elements of categorical arrayC
)C
使用frequency counts.
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);
从令牌化文档中创建Word Cloud
加载示例数据。文件sonnetsPreprocessed.txt
包含莎士比亚十四行诗的预处理版本。该文件包含每行十四行诗,单词被一个空间隔开。提取文本sonnetsPreprocessed.txt
,将文本分成新线字符的文档,然后将文档归为文档。
文件名=“ Sonnetspreprocessed.txt”;str = extractfiletext(filename);textdata = split(str,newline);documents = tokenizedDocument(textData);
使用单词云可视化文档。
图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(袋);
从表中创建字云
加载示例数据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 theWord
和Count
variables respectively.
图WordCloud(tbl,'单词',,,,'数数');title(“十四行诗云”)
从LDA主题创建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)结尾
输入参数
str
-输入文本
字符串数组|character vector|字符向量的单元格数
输入文本,,,,specified as a string array, character vector, or cell array of character vectors.
对于字符串输入,WordCloud
和WordCloudCounts
功能使用英语,日语,德语和韩国令牌化,删除单词范围和单词归一化。
Example:["an example of a short document";"a second short document"]
Data Types:细绳
|char
|细胞
文件
-输入文档
象征性文档
array
输入文档,指定为象征性文档
大批。
WordVar
-Table variable for word data
字符串标量|character vector|numeric index|逻辑向量
单词数据的表变量,指定为字符串标量,字符向量,数字索引或逻辑向量。
Data Types:单身的
|double
|int8
|int16
|int32
|int64
|UINT8
|uint16
|UINT32
|Uint64
|逻辑
|char
|细绳
sizevar
-尺寸数据的表变量
字符串标量|character vector|numeric index|逻辑向量
大小数据的表变量,指定为字符串标量,字符向量,数字索引或逻辑向量。
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
C
-Input categorical data
分类阵列
输入分类数据,指定为分类数组。函数绘制了每个唯一元素的C
with size corresponding to历史图(C)
。
Data Types:categorical
包
-Input model
小词
目的|Bagofngrams
目的
输入袋或n-grams型号,指定为小词
对象或一个Bagofngrams
目的。如果包
是一个Bagofngrams
对象,然后该函数将每个n-gram视为一个单词。
ldaMdl
-Input LDA model
ldamodel
目的
输入LDA模型,指定为ldamodel
目的。
topicidx
-LDA主题索引
非负整数
LDA主题索引,,,,specified as a nonnegative integer.
父母
-父母
数字|控制板|tab
父母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
-显示的最大单词数
100(默认)|非负整数
显示的最大单词数,指定为非负整数。该软件显示maxdisplaywords
最大的单词。
颜色
-单词颜色
[0.2510 0.2510 0.2510]
(默认)|RGB triplet|字符向量包含颜色名称|矩阵
单词颜色,指定为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 from0
至F
。这些值不敏感。因此,颜色代码'#ff8800'
,,,,'#ff8800'
,,,,'#f80'
, 和'#f80'
是等效的。
另外,您可以按名称指定一些常见的颜色。该表列出了命名的颜色选项,等效的RGB三重态和十六进制颜色代码。
颜色名称 | Short Name | RGB三胞胎 | 十六进制的颜色代码 | 外貌 |
---|---|---|---|---|
'红色的' |
'r' |
[1 0 0] |
'#ff0000' |
|
'绿色' |
'g' |
[0 1 0] |
'#00ff00' |
|
'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' |
|
[0.8500 0.3250 0.0980] |
'#D95319' |
|
[0.9290 0.6940 0.1250] |
'#EDB120' |
|
[0.4940 0.1840 0.5560] |
'#7E2F8E' |
|
[0.4660 0.6740 0.1880] |
'#77AC30' |
|
[0.3010 0.7450 0.9330] |
'#4DBEEE' |
|
[0.6350 0.0780 0.1840] |
'#a2142f' |
|
Example:'blue'
Example:[0 0 1]
亮光色
-单词亮点颜色
[0.8510 0.3255 0.0980]
(默认)|RGB triplet|字符向量包含颜色名称
单词亮点颜色,,,,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 from0
至F
。这些值不敏感。因此,颜色代码'#ff8800'
,,,,'#ff8800'
,,,,'#f80'
, 和'#f80'
是等效的。
另外,您可以按名称指定一些常见的颜色。该表列出了命名的颜色选项,等效的RGB三重态和十六进制颜色代码。
颜色名称 | Short Name | RGB三胞胎 | 十六进制的颜色代码 | 外貌 |
---|---|---|---|---|
'红色的' |
'r' |
[1 0 0] |
'#ff0000' |
|
'绿色' |
'g' |
[0 1 0] |
'#00ff00' |
|
'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' |
|
[0.8500 0.3250 0.0980] |
'#D95319' |
|
[0.9290 0.6940 0.1250] |
'#EDB120' |
|
[0.4940 0.1840 0.5560] |
'#7E2F8E' |
|
[0.4660 0.6740 0.1880] |
'#77AC30' |
|
[0.3010 0.7450 0.9330] |
'#4DBEEE' |
|
[0.6350 0.0780 0.1840] |
'#a2142f' |
|
Example:'blue'
Example:[0 0 1]
Shape
-单词云的形状
'椭圆形'
(默认)|'长方形'
单词云图的形状,指定为'椭圆形'
或者'长方形'
。
Example:'长方形'
输出参数
厕所
-WordCloudChart
目的
WordCloudChart
目的
WordCloudChart
目的。您可以修改一个WordCloudChart
创建后。有关更多信息,请参阅WordClodchart属性。
更多关于
Language Considerations
对于字符串输入,WordCloud
和WordCloudCounts
功能使用英语,日语,德语和韩国令牌化,删除单词范围和单词归一化。
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.
版本历史记录
Ouvrir l'exemple
vouspossédezune版本modifiéedecet典范。souhaitez-vous ouvrir cet典范AVEC VOS修改?
命令matlab
Vous Avezcliquésur un lien qui sosideàcettecommande matlab:
pourexécuterla Commande,Saisissez-la dan dan lafenêtredecommande de Matlab。Les导航Web NE支持者PAS LES命令万博1manbetxMATLAB。
您还可以从以下列表中选择一个网站:
如何获得最佳网站性能
选择中国网站(中文或英语)以获得最佳场地性能。其他Mathworks乡村网站未针对您所在的访问进行优化。
美洲
- América Latina(Español)
- 加拿大(English)
- 美国(English)