The documentation shows how Mathematica can attach behavior to words in WordClouds, but I couldn't find anything on retrieving the list of bounding box coordinates.
Is it available to the user?
__
I'm on version 11.2
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityThe documentation shows how Mathematica can attach behavior to words in WordClouds, but I couldn't find anything on retrieving the list of bounding box coordinates.
Is it available to the user?
__
I'm on version 11.2
words = {"apple", "banana", "grapes", "orange", "grapes", "apple",
"grapes", "grapes", "strawberry", "strawberry", "grapes", "grapes",
"banana", "apple", "orange", "grapes", "strawberry", "banana",
"apple", "grapes"};
You can get the bounding boxes using the (hidden) option "BoundingBoxes" -> True
:
wc = WordCloud[words, "BoundingBoxes" -> True, ImagePadding -> 10]
rectangles = Cases[wc, _Rectangle, All]
{Rectangle[{-107,-(81/2)},{107,81/2}],
Rectangle[{-38.5,15.},{38.5,52.}],
Rectangle[{6.5,-48.},{105.5,-21.}],
Rectangle[{-70.,-43.},{-2.,-24.}],
Rectangle[{-26.5,-53.},{10.5,-38.}]}
Show[WordCloud[words, ImagePadding -> 10],
Graphics[{EdgeForm[Gray], Opacity[.2, RandomColor[]], #} & /@ rectangles]]
WordCloud[words, "BoundingBoxes" -> True,
WordOrientation -> "Random", ImagePadding -> 15] /.
r_Rectangle :> { Opacity[.3, RandomColor[]], r}
$Version
"11.3.0 for Microsoft Windows (64-bit) (March 7, 2018)"
This also works in version 12.0.0 (Wolfram Cloud).
Note: I came across this option using
Image`CompositionOperationsDump`WordCloudHiddenOptions // Short
{BitmapOutput -> False, BoundingBoxes-> False, Caching -> False,<<16>>, WordSelectionFunction -> Automatic, WordSpacings -> 1}