为加权过的数据生成词云
产生按国家的人口数量加权的数据.
In[1]:=
years = Range[1716, 2016, 100];
data = Table[
AssociationThread @@
Transpose[
Select[EntityValue[
CountryData[], {"Name",
EntityProperty["Country",
"Population", {"Date" -> DateObject[{year}]}]}],
TrueQ[Last[#] > \!\(\*
NamespaceBox["LinguisticAssistant",
DynamicModuleBox[{Typeset`query$$ = "0 people", Typeset`boxes$$ =
TemplateBox[{"0", "\"people\"", "people", "\"People\""},
"Quantity", SyntaxForm -> Mod],
Typeset`allassumptions$$ = {},
Typeset`assumptions$$ = {}, Typeset`open$$ = {1, 2},
Typeset`querystate$$ = {
"Online" -> True, "Allowed" -> True,
"mparse.jsp" -> 1.326065`6.574109805988145,
"Messages" -> {}}},
DynamicBox[ToBoxes[
AlphaIntegration`LinguisticAssistantBoxes["", 4, Automatic,
Dynamic[Typeset`query$$],
Dynamic[Typeset`boxes$$],
Dynamic[Typeset`allassumptions$$],
Dynamic[Typeset`assumptions$$],
Dynamic[Typeset`open$$],
Dynamic[Typeset`querystate$$]], StandardForm],
ImageSizeCache->{101., {8., 16.}},
TrackedSymbols:>{
Typeset`query$$, Typeset`boxes$$,
Typeset`allassumptions$$, Typeset`assumptions$$,
Typeset`open$$, Typeset`querystate$$}],
DynamicModuleValues:>{},
UndoTrackedVariables:>{Typeset`open$$}],
BaseStyle->{"Deploy"},
DeleteWithContents->True,
Editable->False,
SelectWithContents->True]\)] &]], {year, years}];
构建一个颜色函数,对每个国家始终使用同一个颜色.
In[2]:=
cfun[weight_, string_] :=
cfun[_, string] = RandomChoice[ColorData[97, "ColorList"]]
产生不同年份的一系列词云,其中国家名字的大小按人口数量加权.
In[3]:=
Multicolumn[
MapThread[
WordCloud[#,
PlotLabel -> Style[Framed[#2], 16, Background -> LightGray],
ColorFunction -> cfun, ImageSize -> 300] &, {data, years}], 2,
Appearance -> "Horizontal"]
Out[3]=