ts= textscatter(x,y,str)creates a text scatter plot with elements ofstrat the locations specified by the vectorsxandy, and returns the resultingTextScatterobject.
Create text scatter plot of a word embedding and specify word colors.
Load a pretrained word embedding usingfastTextWordEmbedding. This function requires Text Analytics Toolbox™ Modelfor fastText English 16 Billion Token Word Embeddingsupport package. If this support package is not installed, then the function provides a download link.
emb = fastTextWordEmbedding
emb = wordEmbedding with properties: Dimension: 300 Vocabulary: [1×1000000 string]
Convert the first 500 words to vectors usingword2vec.Vis a matrix of word vectors of length 300.
words = emb.Vocabulary(1:500); V = word2vec(emb,words); size(V)
ans =1×2500 300
Embed the word vectors in two-dimensional space usingtsne.
XY = tsne(V);
Plot the words at the coordinates specified byXYin a 2-D text scatter plot. Specify the word colors to be random.
xvalues, specified as a vector.x,y, andstrmust be of equal length.
Example:[1 2 3]
y—yvalues vector
yvalues, specified as a vector.x,y, andstrmust be of equal length.
Example:[1 2 3]
xy—xandyvalues matrix
xandyvalues, specified as a matrix with two columns.xy(i,1)andxy(i,2)对应于xandyvalues of theith element ofstr, respectively.xymust have thenumel(str)rows.
str—Input text 字符串向量|cell array of character vectors
Input text, specified as a string array or cell array of character vectors.x,y, andstrmust be of equal length.
Example:["one" "two" "three"]
Data Types:string|cell
ax—Axes object axes object
Axes object. If you do not specify an axes object, then the function uses the current axes.
Name-Value Pair Arguments
Specify optional comma-separated pairs ofName,Valuearguments.Nameis the argument name andValueis the corresponding value.Namemust appear inside quotes. You can specify several name and value pair arguments in any order asName1,Value1,...,NameN,ValueN.
Example:'Marker','*'specifies the markers to be asterisks.
TheTextScatterobject properties listed here are only a subset. For a complete list, seeTextScatter Properties.
'TextDensityPercentage'—Percentage of text data to show 60(default) |scalar from 0 through 100
Percentage of text data to show, specified as a scalar from 0 through 100. To show all text, setTextDensityPercentageto 100. To show no text, setTextDensityPercentageto 0.
If you setTextDensityPercentageto 100, then the software does not plot markers.
Example:70
'MaxTextLength'—Maximum length of text labels 40(default) |positive integer
Maximum length of text labels, specified as a positive integer. The software truncates the text labels to this length and adds ellipses at the point of truncation.
'auto'— For each marker, use the same color as the corresponding text labels.
'none'— Do not show markers.
RGB triplet — Use the same color for all the markers in the plot. An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range[0,1]; for example,[0.5 0.6 0.7].
Example:[1 0 0]
'ColorData'—Text colors [](default) |RGB triplet|matrix of RGB triplets|categorical vector
Text colors, specified as one of these values:
RGB triplet — Use the same color for all the text in the plot. An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range[0,1]; for example,[0.5 0.6 0.7].
Three-column matrix of RGB triplets — Use a different color for each text label in the plot. Each row of the matrix defines one color. The number of rows must equal the number of text labels.
Categorical vector — Use a different color for each category in the vector. SpecifyColorDataas a vector the same length asXData. Specify the colors for each category using theColorsproperty
Example:[1 0 0; 0 1 0; 0 0 1]
'Colors'—Category colors matrix of RGB triplets
Category colors, specified as a matrix of RGB triplets. An RGB triplet is a three-element row vector whose elements specify the intensities of the red, green, and blue components of the color. The intensities must be in the range[0,1]; for example,[0.5 0.6 0.7].
By default,Colorsis equal to theColorOrderproperty of the axes object.
TextScatterobject. Usetsto access and modify properties of the text scatter chart after it has been created. For more information, seeTextScatter Properties.
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.