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

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]

enter image description here

rectangles = Cases[wc, _Rectangle, All]


Show[WordCloud[words, ImagePadding -> 10], 
 Graphics[{EdgeForm[Gray], Opacity[.2, RandomColor[]], #} & /@ rectangles]]

enter image description here

WordCloud[words, "BoundingBoxes" -> True, 
  WordOrientation -> "Random", ImagePadding -> 15] /.
    r_Rectangle :> { Opacity[.3, RandomColor[]], r}

enter image description here


"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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.