Word Clouds¤
WordCloud
pydantic-model
¤
Bases: BaseModel
A Pydantic model for WordCloud options.
Config:
arbitrary_types_allowed:Truejson_schema_extra:DocJSONSchema.schema()
Fields:
-
data(single_doc_types | multi_doc_types | DataFrame) -
docs(Optional[int | str | list[int] | list[str]]) -
limit(Optional[int]) -
title(Optional[str]) -
height(int) -
width(int) -
opts(Optional[dict[str, Any]]) -
figure_opts(Optional[dict[str, Any]]) -
round(Optional[int]) -
counts(dict[str, int]) -
cloud(WordCloud | None) -
fig(Optional[Figure])
Source code in lexos/visualization/cloud.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
data: single_doc_types | multi_doc_types | pd.DataFrame
pydantic-field
¤
The data to generate the word cloud from. Accepts data from a string, list of lists or tuples, a dict with terms as keys and counts/frequencies as values, or a dataframe.
docs: Optional[int | str | list[int] | list[str]] = None
pydantic-field
¤
A list of documents to be selected from the DTM.
fig: Optional[plt.Figure] = None
pydantic-field
¤
The matplotlib figure object for the word cloud.
figure_opts: Optional[dict[str, Any]] = {}
pydantic-field
¤
A dict of matplotlib figure options.
height: int = 200
pydantic-field
¤
The height of the word cloud in pixels.
limit: Optional[int] = None
pydantic-field
¤
The maximum number of terms to plot.
opts: Optional[dict[str, Any]] = {'background_color': 'white', 'max_words': 2000, 'contour_width': 0, 'contour_color': 'steelblue'}
pydantic-field
¤
The WordCloud() options.
round: Optional[int] = 0
pydantic-field
¤
An integer to apply a mask that rounds the word cloud. It is best to use 100 or higher for a circular mask, but it will depend on the height and width of the word cloud.
title: Optional[str] = None
pydantic-field
¤
The title of the plot.
width: int = 200
pydantic-field
¤
The width of the word cloud in pixels.
__init__(**data: Any) -> None
¤
Initialize the WordCloud model.
Source code in lexos/visualization/cloud.py
save(path: Path | str, **kwargs: Any) -> None
¤
Save the WordCloud to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
The file path to save the WordCloud image. |
required |
**kwargs
|
Any
|
Additional keyword arguments for |
{}
|
Source code in lexos/visualization/cloud.py
show() -> None
¤
Show the figure if it is hidden.
This is a helper method. It will generally display in a Jupyter notebook.
Source code in lexos/visualization/cloud.py
data: single_doc_types | multi_doc_types | pd.DataFrame
pydantic-field
¤
The data to generate the word cloud from. Accepts data from a string, list of lists or tuples, a dict with terms as keys and counts/frequencies as values, or a dataframe.
docs: Optional[int | str | list[int] | list[str]] = None
pydantic-field
¤
A list of documents to be selected from the DTM.
limit: Optional[int] = None
pydantic-field
¤
The maximum number of terms to plot.
title: Optional[str] = None
pydantic-field
¤
The title of the plot.
height: int = 200
pydantic-field
¤
The height of the word cloud in pixels.
width: int = 200
pydantic-field
¤
The width of the word cloud in pixels.
opts: Optional[dict[str, Any]] = {'background_color': 'white', 'max_words': 2000, 'contour_width': 0, 'contour_color': 'steelblue'}
pydantic-field
¤
The WordCloud() options.
figure_opts: Optional[dict[str, Any]] = {}
pydantic-field
¤
A dict of matplotlib figure options.
round: Optional[int] = 0
pydantic-field
¤
An integer to apply a mask that rounds the word cloud. It is best to use 100 or higher for a circular mask, but it will depend on the height and width of the word cloud.
counts: dict[str, int]
pydantic-field
¤
cloud: PythonWordCloud | None
pydantic-field
¤
fig: Optional[plt.Figure] = None
pydantic-field
¤
The matplotlib figure object for the word cloud.
model_config = ConfigDict(arbitrary_types_allowed=True, json_schema_extra=(DocJSONSchema.schema()))
class-attribute
instance-attribute
¤
__init__(**data: Any) -> None
¤
Initialize the WordCloud model.
Source code in lexos/visualization/cloud.py
save(path: Path | str, **kwargs: Any) -> None
¤
Save the WordCloud to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
The file path to save the WordCloud image. |
required |
**kwargs
|
Any
|
Additional keyword arguments for |
{}
|
Source code in lexos/visualization/cloud.py
show() -> None
¤
Show the figure if it is hidden.
This is a helper method. It will generally display in a Jupyter notebook.
Source code in lexos/visualization/cloud.py
MultiCloud
pydantic-model
¤
Bases: BaseModel
A Pydantic model for creating multiple WordClouds arranged in a grid using the topic_clouds approach.
Config:
arbitrary_types_allowed:Truejson_schema_extra:DocJSONSchema.schema()
Fields:
-
data(list[str] | list[list[str]] | list[Doc] | list[Span] | DTM | DataFrame) -
docs(Optional[int | str | list[int] | list[str]]) -
limit(Optional[int]) -
figsize(tuple[int, int]) -
layout(Optional[str | tuple[int, int]]) -
opts(Optional[dict[str, Any]]) -
round(Optional[int]) -
title(Optional[str]) -
labels(Optional[list[str]]) -
doc_data(Optional[list[dict[str, int | float]]]) -
fig(Optional[Figure]) -
wordcloud(Optional[WordCloud])
Source code in lexos/visualization/cloud.py
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 | |
data: list[str] | list[list[str]] | list[Doc] | list[Span] | DTM | pd.DataFrame
pydantic-field
¤
The data to generate word clouds from. Accepts list of documents, DTM, or DataFrame.
docs: Optional[int | str | list[int] | list[str]] = None
pydantic-field
¤
A list of documents to be selected from the DTM/DataFrame.
fig: Optional[plt.Figure] = None
pydantic-field
¤
The matplotlib figure object for the multi-cloud plot.
figsize: tuple[int, int] = (10, 10)
pydantic-field
¤
The size of the overall figure.
labels: Optional[list[str]] = None
pydantic-field
¤
Labels for each subplot/word cloud.
layout: Optional[str | tuple[int, int]] = 'auto'
pydantic-field
¤
The number of rows and columns in the figure. Default is 'auto'.
limit: Optional[int] = None
pydantic-field
¤
The maximum number of terms to plot per cloud.
opts: Optional[dict[str, Any]] = {'background_color': 'white', 'max_words': 2000, 'contour_width': 0, 'contour_color': 'steelblue'}
pydantic-field
¤
The WordCloud() options applied to each word cloud.
round: Optional[int] = 0
pydantic-field
¤
An integer to apply a mask that rounds each word cloud. It is best to use 100 or higher for a circular mask.
title: Optional[str] = None
pydantic-field
¤
Overall title for the figure.
__init__(**data: Any) -> None
¤
Initialize the MultiCloud model.
Source code in lexos/visualization/cloud.py
save(path: Path | str, **kwargs: Any) -> None
¤
Save the MultiCloud figure to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
The file path to save the MultiCloud image. |
required |
**kwargs
|
Any
|
Additional keyword arguments for |
{}
|
Source code in lexos/visualization/cloud.py
show() -> None
¤
Display the multi-cloud figure.
Source code in lexos/visualization/cloud.py
data: list[str] | list[list[str]] | list[Doc] | list[Span] | DTM | pd.DataFrame
pydantic-field
¤
The data to generate word clouds from. Accepts list of documents, DTM, or DataFrame.
docs: Optional[int | str | list[int] | list[str]] = None
pydantic-field
¤
A list of documents to be selected from the DTM/DataFrame.
limit: Optional[int] = None
pydantic-field
¤
The maximum number of terms to plot per cloud.
figsize: tuple[int, int] = (10, 10)
pydantic-field
¤
The size of the overall figure.
layout: Optional[str | tuple[int, int]] = 'auto'
pydantic-field
¤
The number of rows and columns in the figure. Default is 'auto'.
opts: Optional[dict[str, Any]] = {'background_color': 'white', 'max_words': 2000, 'contour_width': 0, 'contour_color': 'steelblue'}
pydantic-field
¤
The WordCloud() options applied to each word cloud.
round: Optional[int] = 0
pydantic-field
¤
An integer to apply a mask that rounds each word cloud. It is best to use 100 or higher for a circular mask.
title: Optional[str] = None
pydantic-field
¤
Overall title for the figure.
labels: Optional[list[str]] = None
pydantic-field
¤
Labels for each subplot/word cloud.
doc_data: Optional[list[dict[str, int | float]]]
pydantic-field
¤
fig: Optional[plt.Figure] = None
pydantic-field
¤
The matplotlib figure object for the multi-cloud plot.
wordcloud: Optional[PythonWordCloud]
pydantic-field
¤
model_config = ConfigDict(arbitrary_types_allowed=True, json_schema_extra=(DocJSONSchema.schema()))
class-attribute
instance-attribute
¤
__init__(**data: Any) -> None
¤
Initialize the MultiCloud model.
Source code in lexos/visualization/cloud.py
_process_data() -> list[dict[str, int | float]]
¤
Process the input data into individual document dictionaries.
Source code in lexos/visualization/cloud.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
_setup_wordcloud() -> PythonWordCloud
¤
Configure a single WordCloud object to be reused.