WordCloud.jl Documentation
Adding WordCloud.jl
julia> using Pkg
julia> Pkg.add("WordCloud")
Resolving package versions... Updating `~/.julia/packages/WordCloud/nwC7b/docs/Project.toml` [6385f0a0] ~ WordCloud v0.10.7 `~/.julia/packages/WordCloud/nwC7b` ⇒ v0.10.7 Updating `~/.julia/packages/WordCloud/nwC7b/docs/Manifest.toml` [6385f0a0] ~ WordCloud v0.10.7 `~/.julia/packages/WordCloud/nwC7b` ⇒ v0.10.7
Documentation
WordCloud.WordCloud
— ModuleThe WordCloud package is a flexible, fast and exact word cloud generator in julia.
using WordCloud
wc = wordcloud("It's easy to generate word clouds") |> generate!
paint(wc, "wordcloud.svg")
Have a look at the repository: https://github.com/guo-yong-zhi/WordCloud.jl
WordCloud.fit!
— MethodPositional Args
- wc: the wordcloud to fit
- nepoch: training epoch nums
Keyword Args
- patient: number of epochs before repositioning
- reposition: a Bool value to turn on/off teleport, a Float number
p
between 0~1 indicating the repositioning ratio (Minimump
), a Int numbern
equivalent toi -> i >= n
, a Function index::Int -> doteleport::Boll, or a white list collision. - trainer: appoint a training engine
WordCloud.generate!
— MethodPositional Args
- wc: the wordcloud to fit
- nepoch: training epoch nums
Keyword Args
- retry: shrink & retrain times, defaults to 3, set to
1
to disable shrinking - patient: number of epochs before repositioning
- reposition: a Bool value to turn on/off teleport, a Float number
p
between 0~1 indicating the repositioning ratio (Minimump
), a Int numbern
equivalent toi -> i >= n
, a Function index::Int -> doteleport::Boll, or a white list collision. - trainer: appoint a training engine
WordCloud.getangles
— FunctionThe 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index. And the index argument can be ignored to get all values.
WordCloud.getcolors
— FunctionThe 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index. And the index argument can be ignored to get all values.
WordCloud.getfonts
— FunctionThe 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index. And the index argument can be ignored to get all values.
WordCloud.getfontsizes
— FunctionThe 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index. And the index argument can be ignored to get all values.
WordCloud.getimages
— FunctionThe 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index. And the index argument can be ignored to get all values.
WordCloud.getpositions
— FunctionThe 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index. And the index argument can be ignored to get all values. Keyword argment type
can be getshift
or getcenter
.
WordCloud.getsvgimages
— FunctionThe 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index. And the index argument can be ignored to get all values.
WordCloud.getweights
— FunctionThe 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index. And the index argument can be ignored to get all values.
WordCloud.getwords
— FunctionThe 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index. And the index argument can be ignored to get all values.
WordCloud.ignore
— Methodignore some words as if they don't exist, then execute the function. It's the opposite of keep
.
- ignore(fun, wc, ws::String) #ignore a word
- ignore(fun, wc, ws::Set{String}) #ignore all words in ws
- ignore(fun, wc, ws::Vector{String}) #ignore all words in ws
- ignore(fun, wc, inds::Union{Integer, Vector{Integer}})
- ignore(fun, wc::WC, mask::AbstractArray{Bool}) #ignore words. length(mask)==length(wc)
WordCloud.initwords!
— MethodInitialize word's images and other resources with specified style
WordCloud.keep
— Methodkeep some words and ignore the others, then execute the function. It's the opposite of ignore
.
- keep(fun, wc, ws::String) #keep a word
- keep(fun, wc, ws::Set{String}) #kepp all words in ws
- keep(fun, wc, ws::Vector{String}) #keep all words in ws
- keep(fun, wc, inds::Union{Integer, Vector{Integer}})
- keep(fun, wc::WC, mask::AbstractArray{Bool}) #keep words. length(mask)==length(wc)
WordCloud.loadmask
— Methodload a img as mask, recolor, or resize, etc
examples
- loadmask(open("res/heart.jpg"), 256, 256) #resize to 256*256
- loadmask("res/heart.jpg", ratio=0.3) #scale 0.3
- loadmask("res/heart.jpg", color="red", ratio=2) #set forecolor
- loadmask("res/heart.jpg", transparent=rgba->maximum(rgba[1:3])*(rgba[4]/255)>128) #set transparent with a Function
- loadmask("res/heart.jpg", color="red", transparent=(1,1,1)) #set forecolor and transparent
- loadmask("res/heart.svg") #other arguments are not supported
padding: an Integer or a tuple of two Integers About orther keyword arguments like outline, linecolor, smoothness, see function outline
.
WordCloud.paint
— Methodexamples
- paint(wc::WC)
- paint(wc::WC, background=false) #no background
- paint(wc::WC, background=outline(wc.mask)) #use a new background
- paint(wc::WC, ratio=0.5) #resize the result
- paint(wc::WC, "result.png", ratio=0.5) #save as png file, other bitmap formats may also work
- paint(wc::WC, "result.svg") #save as svg file
WordCloud.paintsvg
— Methodlike paint
but export svg
WordCloud.pin
— Methodpin some words as if they were part of the background, then execute the function.
- pin(fun, wc, ws::String) #pin a word
- pin(fun, wc, ws::Set{String}) #pin all words in ws
- pin(fun, wc, ws::Vector{String}) #pin all words in ws
- pin(fun, wc, inds::Union{Integer, Vector{Integer}})
- pin(fun, wc::WC, mask::AbstractArray{Bool}) #pin words. length(mask)==length(wc)
WordCloud.placewords!
— Method- placewords!(wc)
- placewords!(wc, style=:uniform)
- placewords!(wc, style=:gathering)
- placewords!(wc, style=:gathering, level=5) #
level
controls the intensity of gathering, typically between 4 and 6, defaults to 5. - placewords!(wc, style=:gathering, level=6, rt=0) #rt=0, rectangle; rt=1, ellipse; rt=2, rhombus. defaults to 1.
There is also a keyword argument centeredword
. e.g. centeredword=1
, centeredword="Alice"
, centeredword=false
When you have set style=:gathering
, you should disable repositioning in generate!
at the same time, especially for big words. e.g. generate!(wc, reposition=0.7)
. The keyword argument reorder
is a function to reorder the words, which affects the order of placement. Like reverse
, WordCloud.shuffle
.
WordCloud.recolor!
— Methodrecolor the words in wc
in different styles with the background picture. The styles supported are :average
, :main
, :clipping
, :blending
, and :reset (to undo all effects of others). e.g.
- recolor!(wc, style=:average)
- recolor!(wc, style=:main)
- recolor!(wc, style=:clipping, background=blur(getmask(wc))) #
background
is optional - recolor!(wc, style=:blending, alpha=0.3) #
background
andalpha
are optional - recolor!(wc, style=:reset)
The effects of :average
, :main
and :clipping
are only determined by the background
. But the effect of :blending
is also affected by the previous word color. Therefore, :blending
can also be used in combination with others The results of clipping
and blending
can not be exported as SVG files, use PNG instead.
WordCloud.rescale!
— Methodrescale!(wc::WC, ratio::Real) Rescale all words's size. set ratio
<1 to shrink, set ratio
>1 to expand.
WordCloud.runexample
— FunctionAvailable values: [:alice, :animation1, :animation2, :benchmark, :compare, :compare2, :custom, :fromweb, :gathering, :highdensity, :juliadoc, :lettermask, :logo, :nomask, :outline, :pattern, :qianziwen, :random, :recolor, :semantic, :series, :中文]
WordCloud.setangles!
— MethodThe 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index, the 3rd argument is the value to assign.
WordCloud.setcolors!
— MethodThe 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index, the 3rd argument is the value to assign.
WordCloud.setfonts!
— MethodThe 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index, the 3rd argument is the value to assign.
WordCloud.setfontsizes!
— MethodThe 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index, the 3rd argument is the value to assign.
WordCloud.setimages!
— MethodThe 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index, the 3rd argument is the value to assign.
WordCloud.setpositions!
— MethodThe 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index, the 3rd argument is the value to assign. Keyword argment type
can be setshift!
or setcenter!
.
WordCloud.setsvgimages!
— MethodThe 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index, the 3rd argument is the value to assign.
WordCloud.setweights!
— MethodThe 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index, the 3rd argument is the value to assign.
WordCloud.setwords!
— MethodThe 1st argument is wordcloud, the 2nd argument is index which can be string, number, list, or any other standard supported index, the 3rd argument is the value to assign.
WordCloud.showexample
— FunctionAvailable values: [:alice, :animation1, :animation2, :benchmark, :compare, :compare2, :custom, :fromweb, :gathering, :highdensity, :juliadoc, :lettermask, :logo, :nomask, :outline, :pattern, :qianziwen, :random, :recolor, :semantic, :series, :中文]
WordCloud.wordcloud
— MethodPositional Arguments
Positional arguments are used to specify words and weights, and can be in different forms, such as Tuple or Dict, etc.
- words::AbstractVector{<:AbstractString}, weights::AbstractVector{<:Real}
- words_weights::Tuple
- counter::AbstractDict
- counter::AbstractVector{<:Pair}
Optional Keyword Arguments
style keyword arguments
- colors = "black" #all same color
- colors = ("black", (0.5,0.5,0.7), "yellow", "#ff0000", 0.2) #choose entries randomly
- colors = ["black", (0.5,0.5,0.7), "yellow", "red", (0.5,0.5,0.7), 0.2, ......] #use entries sequentially in cycle
- colors = :seaborn_dark #using a preset scheme. see
WordCloud.colorschemes
for all supported Symbols. andWordCloud.displayschemes()
may be helpful. - angles = 0 #all same angle
- angles = (0, 90, 45) #choose entries randomly
- angles = 0:180 #choose entries randomly
- angles = [0, 22, 4, 1, 100, 10, ......] #use entries sequentially in cycle
- fonts = "Serif Bold" #all same font
- fonts = ("Arial", "Times New Roman", "Tahoma") #choose entries randomly
- fonts = ["Arial", "Times New Roman", "Tahoma", ......] #use entries sequentially in cycle
- density = 0.55 #default 0.5
- spacing = 1 #minimum spacing between words
mask keyword arguments
- mask = loadmask("res/heart.jpg", 256, 256) #see the doc of
loadmask
- mask = loadmask("res/heart.jpg", color="red", ratio=2) #see the doc of
loadmask
- mask = "res/heart.jpg" #shorthand for loadmask("res/heart.jpg")
- mask = shape(ellipse, 800, 600, color="white", backgroundcolor=(0,0,0,0)) #See the doc of
shape
. - mask = box #mask can also be one of
box
,ellipse
,squircle
,ngon
andstar
. See the doc ofshape
. - masksize: Can be a tuple
(width, height)
or just a single number as a side length hint. - backgroundsize: See
shape
. Need to be used withmasksize
to specify the padding size. - maskcolor: like "black", "#ff0000", (0.5,0.5,0.7), 0.2, or :default, :original (keep it unchanged), :auto (auto recolor the mask).
- backgroundcolor: like "black", "#ff0000", (0.5,0.5,0.7), 0.2, or :default, :original, :maskcolor, :auto (random choose between :original and :maskcolor)
- outline, linecolor, smoothness: See function
shape
andoutline
. - transparent = (1,0,0) #set the transparent color in mask
- transparent = nothing #no transparent color
- transparent = c->(c[1]+c[2]+c[3])/3*(c[4]/255)>128) #set transparent with a Function.
c
is a (r,g,b,a) Tuple.
–-NOTE Some arguments depend on whether or not the mask
is given or the type of the given mask
.
other keyword arguments
- style, centeredword, reorder, rt, level: config the style of
placewords!
. See the doc ofplacewords!
. - state = placewords! #default setting, will initialize word's position
- state = generate! #get result directly
- state = initwords! #only initialize resources, such as rendering word images
- state = identity #do nothing
The keyword argument state
is a function. It will be called after the wordcloud
object constructed. This will set the object to a specific state. –-NOTE
- After getting the
wordcloud
object, these steps are needed to get the result picture: initwords! -> placewords! -> generate! -> paint - You can skip
placewords!
and/orinitwords!
, and these operations will be performed automatically with default parameters
Gallery
Index
WordCloud.WordCloud
WordCloud.fit!
WordCloud.generate!
WordCloud.getangles
WordCloud.getcolors
WordCloud.getfonts
WordCloud.getfontsizes
WordCloud.getimages
WordCloud.getpositions
WordCloud.getsvgimages
WordCloud.getweights
WordCloud.getwords
WordCloud.ignore
WordCloud.initwords!
WordCloud.keep
WordCloud.loadmask
WordCloud.paint
WordCloud.paintsvg
WordCloud.pin
WordCloud.placewords!
WordCloud.recolor!
WordCloud.rescale!
WordCloud.runexample
WordCloud.setangles!
WordCloud.setcolors!
WordCloud.setfonts!
WordCloud.setfontsizes!
WordCloud.setimages!
WordCloud.setpositions!
WordCloud.setsvgimages!
WordCloud.setweights!
WordCloud.setwords!
WordCloud.showexample
WordCloud.wordcloud