truewordcloud 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- truewordcloud-1.0.0/.gitattributes +2 -0
- truewordcloud-1.0.0/.gitignore +36 -0
- truewordcloud-1.0.0/LICENSE +21 -0
- truewordcloud-1.0.0/PKG-INFO +257 -0
- truewordcloud-1.0.0/README.md +221 -0
- truewordcloud-1.0.0/docs/GITHUB_SETUP_GUIDE.md +202 -0
- truewordcloud-1.0.0/examples/README.md +31 -0
- truewordcloud-1.0.0/examples/example_greedy.png +0 -0
- truewordcloud-1.0.0/examples/example_greedy_basic.png +0 -0
- truewordcloud-1.0.0/examples/example_greedy_colors.png +0 -0
- truewordcloud-1.0.0/examples/example_greedy_custom_font.png +0 -0
- truewordcloud-1.0.0/examples/example_square.png +0 -0
- truewordcloud-1.0.0/examples/example_square_categorical.png +0 -0
- truewordcloud-1.0.0/examples/example_square_keyness.png +0 -0
- truewordcloud-1.0.0/examples/example_square_large.png +0 -0
- truewordcloud-1.0.0/examples.py +236 -0
- truewordcloud-1.0.0/pyproject.toml +44 -0
- truewordcloud-1.0.0/requirements-dev.txt +5 -0
- truewordcloud-1.0.0/requirements.txt +3 -0
- truewordcloud-1.0.0/setup.cfg +4 -0
- truewordcloud-1.0.0/setup.py +45 -0
- truewordcloud-1.0.0/tests/__init__.py +1 -0
- truewordcloud-1.0.0/tests/test_truewordcloud.py +257 -0
- truewordcloud-1.0.0/truewordcloud.egg-info/PKG-INFO +257 -0
- truewordcloud-1.0.0/truewordcloud.egg-info/SOURCES.txt +27 -0
- truewordcloud-1.0.0/truewordcloud.egg-info/dependency_links.txt +1 -0
- truewordcloud-1.0.0/truewordcloud.egg-info/requires.txt +3 -0
- truewordcloud-1.0.0/truewordcloud.egg-info/top_level.txt +1 -0
- truewordcloud-1.0.0/truewordcloud.py +579 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# Byte-compiled / optimized files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# Distribution / packaging
|
|
7
|
+
build/
|
|
8
|
+
dist/
|
|
9
|
+
*.egg-info/
|
|
10
|
+
*.egg
|
|
11
|
+
|
|
12
|
+
# Testing
|
|
13
|
+
.pytest_cache/
|
|
14
|
+
.coverage
|
|
15
|
+
htmlcov/
|
|
16
|
+
|
|
17
|
+
# Virtual environments
|
|
18
|
+
.venv/
|
|
19
|
+
venv/
|
|
20
|
+
env/
|
|
21
|
+
|
|
22
|
+
# IDEs
|
|
23
|
+
.vscode/
|
|
24
|
+
.idea/
|
|
25
|
+
*.swp
|
|
26
|
+
*~
|
|
27
|
+
|
|
28
|
+
# OS files
|
|
29
|
+
.DS_Store
|
|
30
|
+
Thumbs.db
|
|
31
|
+
|
|
32
|
+
# Generated word clouds (ignore all PNGs except examples folder)
|
|
33
|
+
*.png
|
|
34
|
+
!examples/*.png
|
|
35
|
+
|
|
36
|
+
# Project specific
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Laurence Anthony
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: truewordcloud
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Value-proportional word cloud generator with true size relationships
|
|
5
|
+
Home-page: https://github.com/laurenceanthony/truewordcloud
|
|
6
|
+
Author: Laurence Anthony
|
|
7
|
+
Author-email: Laurence Anthony <anthony@antlabsolutions.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
Project-URL: Homepage, https://github.com/laurenceanthony/truewordcloud
|
|
10
|
+
Project-URL: Bug Reports, https://github.com/laurenceanthony/truewordcloud/issues
|
|
11
|
+
Project-URL: Source, https://github.com/laurenceanthony/truewordcloud
|
|
12
|
+
Keywords: wordcloud,visualization,text-analysis,frequency,linguistics,data-visualization
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Science/Research
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Topic :: Scientific/Engineering :: Visualization
|
|
17
|
+
Classifier: Topic :: Text Processing :: Linguistic
|
|
18
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
19
|
+
Classifier: Programming Language :: Python :: 3
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
26
|
+
Requires-Python: >=3.7
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE
|
|
29
|
+
Requires-Dist: Pillow>=8.0.0
|
|
30
|
+
Requires-Dist: numpy>=1.19.0
|
|
31
|
+
Requires-Dist: matplotlib>=3.3.0
|
|
32
|
+
Dynamic: author
|
|
33
|
+
Dynamic: home-page
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
Dynamic: requires-python
|
|
36
|
+
|
|
37
|
+
# TrueWordCloud
|
|
38
|
+
|
|
39
|
+
**Value-Proportional Word Cloud Generator**
|
|
40
|
+
|
|
41
|
+
A word cloud generator that maintains TRUE proportional relationships between values. Unlike traditional word clouds that arbitrarily resize words to fit a canvas, TrueWordCloud ensures font sizes are ALWAYS proportional to the input values.
|
|
42
|
+
|
|
43
|
+
## Key Features
|
|
44
|
+
|
|
45
|
+
- ✅ **True Proportionality** - Font sizes strictly proportional to input values (no squeezing/normalization)
|
|
46
|
+
- 🎨 **Two Layout Algorithms** - Choose between 'greedy' (fast, deterministic) and 'square' (compact, randomized)
|
|
47
|
+
- 📐 **Dynamic Canvas** - Canvas size determined by content, not pre-fixed dimensions
|
|
48
|
+
- 🔢 **Any Numeric Values** - Works with frequencies, keyness scores, TF-IDF, probabilities, etc.
|
|
49
|
+
- 🎯 **No Overlaps** - Guaranteed non-overlapping word placement
|
|
50
|
+
- 🌈 **Custom Colors** - Flexible color function support
|
|
51
|
+
|
|
52
|
+
## Installation
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install truewordcloud
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Or install from source:
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
git clone https://github.com/laurenceanthony/truewordcloud.git
|
|
62
|
+
cd truewordcloud
|
|
63
|
+
pip install -e .
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Quick Start
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
from truewordcloud import TrueWordCloud
|
|
70
|
+
|
|
71
|
+
# Simple usage
|
|
72
|
+
values = {'python': 100, 'data': 80, 'science': 75, 'visualization': 60}
|
|
73
|
+
twc = TrueWordCloud(values=values)
|
|
74
|
+
image = twc.generate()
|
|
75
|
+
image.save('wordcloud.png')
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Layout Algorithms
|
|
79
|
+
|
|
80
|
+
### Greedy Spiral (method='greedy')
|
|
81
|
+
|
|
82
|
+
**Best for: Speed, reproducibility, circular aesthetics**
|
|
83
|
+
|
|
84
|
+
- ⚡ Fast spiral placement from center outward
|
|
85
|
+
- 🔒 Deterministic (same input → same output)
|
|
86
|
+
- 🎯 Creates radial/circular patterns
|
|
87
|
+
- ✅ Ideal for scientific papers, reports, consistent branding
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
twc = TrueWordCloud(values=values, method='greedy')
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Square Packing (method='square')
|
|
94
|
+
|
|
95
|
+
**Best for: Compact layouts, gap filling, visual variety**
|
|
96
|
+
|
|
97
|
+
- 📦 Center-outward square packing with intelligent gap filling
|
|
98
|
+
- 🎲 Randomized (varied layouts each run)
|
|
99
|
+
- 📐 Maintains roughly square aspect ratio (width ≈ height)
|
|
100
|
+
- ✅ Ideal for presentations, posters, artistic displays
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
twc = TrueWordCloud(values=values, method='square')
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Advanced Usage
|
|
107
|
+
|
|
108
|
+
### Custom Colors
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
def color_func(word, freq, norm_freq):
|
|
112
|
+
# norm_freq is between 0 and 1
|
|
113
|
+
if norm_freq > 0.7:
|
|
114
|
+
return (255, 0, 0) # Red for high frequency
|
|
115
|
+
elif norm_freq > 0.4:
|
|
116
|
+
return (0, 0, 255) # Blue for medium
|
|
117
|
+
else:
|
|
118
|
+
return (128, 128, 128) # Gray for low
|
|
119
|
+
|
|
120
|
+
twc = TrueWordCloud(values=values, color_func=color_func)
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### All Parameters
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
twc = TrueWordCloud(
|
|
127
|
+
values={'word': 100, 'cloud': 50}, # Required: word -> value mapping
|
|
128
|
+
method='greedy', # 'greedy' or 'square'
|
|
129
|
+
base_font_size=100, # Font size for max value word
|
|
130
|
+
font_path='/path/to/font.ttf', # Custom font (auto-detected if None)
|
|
131
|
+
min_font_size=10, # Minimum font size
|
|
132
|
+
background_color=(255, 255, 255), # RGB tuple
|
|
133
|
+
margin=2, # Pixels between words
|
|
134
|
+
color_func=None # Custom color function
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
# Generate with statistics
|
|
138
|
+
image, stats = twc.generate_with_stats()
|
|
139
|
+
print(stats) # {'num_words': 2, 'size_range': (50, 100), 'canvas_size': (800, 600), 'method': 'greedy'}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
## Comparison with Traditional Word Clouds
|
|
143
|
+
|
|
144
|
+
| Feature | TrueWordCloud | Traditional Word Clouds |
|
|
145
|
+
|---------|---------------|------------------------|
|
|
146
|
+
| Proportionality | ✅ Strict (font_size ∝ value) | ❌ Arbitrary resizing to fit |
|
|
147
|
+
| Canvas Size | Dynamic (fits content) | Fixed (pre-defined) |
|
|
148
|
+
| Reproducibility | ✅ Greedy method | Sometimes |
|
|
149
|
+
| Layout Options | 2 algorithms | Usually 1 |
|
|
150
|
+
| Value Types | Any numeric | Usually just frequencies |
|
|
151
|
+
|
|
152
|
+
## Why True Proportionality Matters
|
|
153
|
+
|
|
154
|
+
Traditional word clouds often **lie** about the data:
|
|
155
|
+
- A word with value 100 might be rendered at 80pt
|
|
156
|
+
- A word with value 50 might be rendered at 75pt
|
|
157
|
+
- Ratios like 2:1 become 1.07:1
|
|
158
|
+
|
|
159
|
+
**TrueWordCloud guarantees:**
|
|
160
|
+
- Value 100 → 100pt, Value 50 → 50pt
|
|
161
|
+
- Ratios are preserved: 2:1 stays 2:1
|
|
162
|
+
- Visual size accurately represents data magnitude
|
|
163
|
+
|
|
164
|
+
## Use Cases
|
|
165
|
+
|
|
166
|
+
- **Linguistic Analysis** - Word frequencies, keyness scores, TF-IDF
|
|
167
|
+
- **Survey Results** - Response counts, satisfaction scores
|
|
168
|
+
- **Scientific Papers** - Maintaining accurate proportional relationships
|
|
169
|
+
- **Marketing** - Brand mentions, sentiment scores
|
|
170
|
+
- **Education** - Concept importance, study time allocation
|
|
171
|
+
|
|
172
|
+
## Requirements
|
|
173
|
+
|
|
174
|
+
- Python 3.7+
|
|
175
|
+
- Pillow (PIL)
|
|
176
|
+
- numpy
|
|
177
|
+
- matplotlib (for font detection)
|
|
178
|
+
|
|
179
|
+
## License
|
|
180
|
+
|
|
181
|
+
MIT License - see LICENSE file for details
|
|
182
|
+
|
|
183
|
+
## Contributing
|
|
184
|
+
|
|
185
|
+
Contributions welcome! Please open an issue or submit a pull request.
|
|
186
|
+
|
|
187
|
+
## Citation
|
|
188
|
+
|
|
189
|
+
If you use TrueWordCloud in academic work, please cite:
|
|
190
|
+
|
|
191
|
+
```
|
|
192
|
+
@software{truewordcloud2026,
|
|
193
|
+
title={TrueWordCloud: Value-Proportional Word Cloud Generator},
|
|
194
|
+
author={Laurence Anthony},
|
|
195
|
+
year={2026},
|
|
196
|
+
url={https://github.com/laurenceanthony/truewordcloud}
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
## Examples
|
|
201
|
+
|
|
202
|
+
### Frequency Data
|
|
203
|
+
```python
|
|
204
|
+
word_frequencies = {
|
|
205
|
+
'the': 1000, 'Python': 500, 'data': 400, 'analysis': 300,
|
|
206
|
+
'machine': 250, 'learning': 250, 'algorithm': 200
|
|
207
|
+
}
|
|
208
|
+
twc = TrueWordCloud(values=word_frequencies, method='greedy')
|
|
209
|
+
twc.generate().save('frequencies.png')
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
### Keyness Scores
|
|
213
|
+
```python
|
|
214
|
+
keyness_scores = {
|
|
215
|
+
'significant': 12.5, 'analysis': 8.3, 'corpus': 6.7,
|
|
216
|
+
'frequency': 5.2, 'text': 4.1
|
|
217
|
+
}
|
|
218
|
+
twc = TrueWordCloud(values=keyness_scores, method='square', base_font_size=50)
|
|
219
|
+
twc.generate().save('keyness.png')
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### With Custom Styling
|
|
223
|
+
```python
|
|
224
|
+
from PIL import ImageColor
|
|
225
|
+
|
|
226
|
+
def rainbow_color(word, freq, norm_freq):
|
|
227
|
+
# Rainbow gradient based on frequency
|
|
228
|
+
hue = int(norm_freq * 270) # 0 (red) to 270 (blue)
|
|
229
|
+
return ImageColor.getrgb(f'hsl({hue}, 100%, 50%)')
|
|
230
|
+
|
|
231
|
+
twc = TrueWordCloud(
|
|
232
|
+
values=word_frequencies,
|
|
233
|
+
method='square',
|
|
234
|
+
color_func=rainbow_color,
|
|
235
|
+
background_color=(0, 0, 0), # Black background
|
|
236
|
+
margin=5
|
|
237
|
+
)
|
|
238
|
+
twc.generate().save('rainbow.png')
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
## FAQ
|
|
242
|
+
|
|
243
|
+
**Q: Why are the layouts different sizes?**
|
|
244
|
+
A: Canvas size is determined by content. More words or higher values = larger canvas. This maintains true proportions.
|
|
245
|
+
|
|
246
|
+
**Q: Can I fix the canvas size?**
|
|
247
|
+
A: Not directly, as that would require resizing words (breaking true proportionality). Instead, adjust `base_font_size` to control overall scale.
|
|
248
|
+
|
|
249
|
+
**Q: Which method should I use?**
|
|
250
|
+
A: Use `greedy` for speed and reproducibility. Use `square` for compact layouts and visual variety.
|
|
251
|
+
|
|
252
|
+
**Q: How do I make words fit in a specific area?**
|
|
253
|
+
A: Reduce `base_font_size` until the generated canvas is the desired size.
|
|
254
|
+
|
|
255
|
+
---
|
|
256
|
+
|
|
257
|
+
**Made with ❤️ for accurate data visualization**
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
# TrueWordCloud
|
|
2
|
+
|
|
3
|
+
**Value-Proportional Word Cloud Generator**
|
|
4
|
+
|
|
5
|
+
A word cloud generator that maintains TRUE proportional relationships between values. Unlike traditional word clouds that arbitrarily resize words to fit a canvas, TrueWordCloud ensures font sizes are ALWAYS proportional to the input values.
|
|
6
|
+
|
|
7
|
+
## Key Features
|
|
8
|
+
|
|
9
|
+
- ✅ **True Proportionality** - Font sizes strictly proportional to input values (no squeezing/normalization)
|
|
10
|
+
- 🎨 **Two Layout Algorithms** - Choose between 'greedy' (fast, deterministic) and 'square' (compact, randomized)
|
|
11
|
+
- 📐 **Dynamic Canvas** - Canvas size determined by content, not pre-fixed dimensions
|
|
12
|
+
- 🔢 **Any Numeric Values** - Works with frequencies, keyness scores, TF-IDF, probabilities, etc.
|
|
13
|
+
- 🎯 **No Overlaps** - Guaranteed non-overlapping word placement
|
|
14
|
+
- 🌈 **Custom Colors** - Flexible color function support
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
pip install truewordcloud
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Or install from source:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
git clone https://github.com/laurenceanthony/truewordcloud.git
|
|
26
|
+
cd truewordcloud
|
|
27
|
+
pip install -e .
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Quick Start
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
from truewordcloud import TrueWordCloud
|
|
34
|
+
|
|
35
|
+
# Simple usage
|
|
36
|
+
values = {'python': 100, 'data': 80, 'science': 75, 'visualization': 60}
|
|
37
|
+
twc = TrueWordCloud(values=values)
|
|
38
|
+
image = twc.generate()
|
|
39
|
+
image.save('wordcloud.png')
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Layout Algorithms
|
|
43
|
+
|
|
44
|
+
### Greedy Spiral (method='greedy')
|
|
45
|
+
|
|
46
|
+
**Best for: Speed, reproducibility, circular aesthetics**
|
|
47
|
+
|
|
48
|
+
- ⚡ Fast spiral placement from center outward
|
|
49
|
+
- 🔒 Deterministic (same input → same output)
|
|
50
|
+
- 🎯 Creates radial/circular patterns
|
|
51
|
+
- ✅ Ideal for scientific papers, reports, consistent branding
|
|
52
|
+
|
|
53
|
+
```python
|
|
54
|
+
twc = TrueWordCloud(values=values, method='greedy')
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
### Square Packing (method='square')
|
|
58
|
+
|
|
59
|
+
**Best for: Compact layouts, gap filling, visual variety**
|
|
60
|
+
|
|
61
|
+
- 📦 Center-outward square packing with intelligent gap filling
|
|
62
|
+
- 🎲 Randomized (varied layouts each run)
|
|
63
|
+
- 📐 Maintains roughly square aspect ratio (width ≈ height)
|
|
64
|
+
- ✅ Ideal for presentations, posters, artistic displays
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
twc = TrueWordCloud(values=values, method='square')
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
## Advanced Usage
|
|
71
|
+
|
|
72
|
+
### Custom Colors
|
|
73
|
+
|
|
74
|
+
```python
|
|
75
|
+
def color_func(word, freq, norm_freq):
|
|
76
|
+
# norm_freq is between 0 and 1
|
|
77
|
+
if norm_freq > 0.7:
|
|
78
|
+
return (255, 0, 0) # Red for high frequency
|
|
79
|
+
elif norm_freq > 0.4:
|
|
80
|
+
return (0, 0, 255) # Blue for medium
|
|
81
|
+
else:
|
|
82
|
+
return (128, 128, 128) # Gray for low
|
|
83
|
+
|
|
84
|
+
twc = TrueWordCloud(values=values, color_func=color_func)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### All Parameters
|
|
88
|
+
|
|
89
|
+
```python
|
|
90
|
+
twc = TrueWordCloud(
|
|
91
|
+
values={'word': 100, 'cloud': 50}, # Required: word -> value mapping
|
|
92
|
+
method='greedy', # 'greedy' or 'square'
|
|
93
|
+
base_font_size=100, # Font size for max value word
|
|
94
|
+
font_path='/path/to/font.ttf', # Custom font (auto-detected if None)
|
|
95
|
+
min_font_size=10, # Minimum font size
|
|
96
|
+
background_color=(255, 255, 255), # RGB tuple
|
|
97
|
+
margin=2, # Pixels between words
|
|
98
|
+
color_func=None # Custom color function
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
# Generate with statistics
|
|
102
|
+
image, stats = twc.generate_with_stats()
|
|
103
|
+
print(stats) # {'num_words': 2, 'size_range': (50, 100), 'canvas_size': (800, 600), 'method': 'greedy'}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## Comparison with Traditional Word Clouds
|
|
107
|
+
|
|
108
|
+
| Feature | TrueWordCloud | Traditional Word Clouds |
|
|
109
|
+
|---------|---------------|------------------------|
|
|
110
|
+
| Proportionality | ✅ Strict (font_size ∝ value) | ❌ Arbitrary resizing to fit |
|
|
111
|
+
| Canvas Size | Dynamic (fits content) | Fixed (pre-defined) |
|
|
112
|
+
| Reproducibility | ✅ Greedy method | Sometimes |
|
|
113
|
+
| Layout Options | 2 algorithms | Usually 1 |
|
|
114
|
+
| Value Types | Any numeric | Usually just frequencies |
|
|
115
|
+
|
|
116
|
+
## Why True Proportionality Matters
|
|
117
|
+
|
|
118
|
+
Traditional word clouds often **lie** about the data:
|
|
119
|
+
- A word with value 100 might be rendered at 80pt
|
|
120
|
+
- A word with value 50 might be rendered at 75pt
|
|
121
|
+
- Ratios like 2:1 become 1.07:1
|
|
122
|
+
|
|
123
|
+
**TrueWordCloud guarantees:**
|
|
124
|
+
- Value 100 → 100pt, Value 50 → 50pt
|
|
125
|
+
- Ratios are preserved: 2:1 stays 2:1
|
|
126
|
+
- Visual size accurately represents data magnitude
|
|
127
|
+
|
|
128
|
+
## Use Cases
|
|
129
|
+
|
|
130
|
+
- **Linguistic Analysis** - Word frequencies, keyness scores, TF-IDF
|
|
131
|
+
- **Survey Results** - Response counts, satisfaction scores
|
|
132
|
+
- **Scientific Papers** - Maintaining accurate proportional relationships
|
|
133
|
+
- **Marketing** - Brand mentions, sentiment scores
|
|
134
|
+
- **Education** - Concept importance, study time allocation
|
|
135
|
+
|
|
136
|
+
## Requirements
|
|
137
|
+
|
|
138
|
+
- Python 3.7+
|
|
139
|
+
- Pillow (PIL)
|
|
140
|
+
- numpy
|
|
141
|
+
- matplotlib (for font detection)
|
|
142
|
+
|
|
143
|
+
## License
|
|
144
|
+
|
|
145
|
+
MIT License - see LICENSE file for details
|
|
146
|
+
|
|
147
|
+
## Contributing
|
|
148
|
+
|
|
149
|
+
Contributions welcome! Please open an issue or submit a pull request.
|
|
150
|
+
|
|
151
|
+
## Citation
|
|
152
|
+
|
|
153
|
+
If you use TrueWordCloud in academic work, please cite:
|
|
154
|
+
|
|
155
|
+
```
|
|
156
|
+
@software{truewordcloud2026,
|
|
157
|
+
title={TrueWordCloud: Value-Proportional Word Cloud Generator},
|
|
158
|
+
author={Laurence Anthony},
|
|
159
|
+
year={2026},
|
|
160
|
+
url={https://github.com/laurenceanthony/truewordcloud}
|
|
161
|
+
}
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
## Examples
|
|
165
|
+
|
|
166
|
+
### Frequency Data
|
|
167
|
+
```python
|
|
168
|
+
word_frequencies = {
|
|
169
|
+
'the': 1000, 'Python': 500, 'data': 400, 'analysis': 300,
|
|
170
|
+
'machine': 250, 'learning': 250, 'algorithm': 200
|
|
171
|
+
}
|
|
172
|
+
twc = TrueWordCloud(values=word_frequencies, method='greedy')
|
|
173
|
+
twc.generate().save('frequencies.png')
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### Keyness Scores
|
|
177
|
+
```python
|
|
178
|
+
keyness_scores = {
|
|
179
|
+
'significant': 12.5, 'analysis': 8.3, 'corpus': 6.7,
|
|
180
|
+
'frequency': 5.2, 'text': 4.1
|
|
181
|
+
}
|
|
182
|
+
twc = TrueWordCloud(values=keyness_scores, method='square', base_font_size=50)
|
|
183
|
+
twc.generate().save('keyness.png')
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### With Custom Styling
|
|
187
|
+
```python
|
|
188
|
+
from PIL import ImageColor
|
|
189
|
+
|
|
190
|
+
def rainbow_color(word, freq, norm_freq):
|
|
191
|
+
# Rainbow gradient based on frequency
|
|
192
|
+
hue = int(norm_freq * 270) # 0 (red) to 270 (blue)
|
|
193
|
+
return ImageColor.getrgb(f'hsl({hue}, 100%, 50%)')
|
|
194
|
+
|
|
195
|
+
twc = TrueWordCloud(
|
|
196
|
+
values=word_frequencies,
|
|
197
|
+
method='square',
|
|
198
|
+
color_func=rainbow_color,
|
|
199
|
+
background_color=(0, 0, 0), # Black background
|
|
200
|
+
margin=5
|
|
201
|
+
)
|
|
202
|
+
twc.generate().save('rainbow.png')
|
|
203
|
+
```
|
|
204
|
+
|
|
205
|
+
## FAQ
|
|
206
|
+
|
|
207
|
+
**Q: Why are the layouts different sizes?**
|
|
208
|
+
A: Canvas size is determined by content. More words or higher values = larger canvas. This maintains true proportions.
|
|
209
|
+
|
|
210
|
+
**Q: Can I fix the canvas size?**
|
|
211
|
+
A: Not directly, as that would require resizing words (breaking true proportionality). Instead, adjust `base_font_size` to control overall scale.
|
|
212
|
+
|
|
213
|
+
**Q: Which method should I use?**
|
|
214
|
+
A: Use `greedy` for speed and reproducibility. Use `square` for compact layouts and visual variety.
|
|
215
|
+
|
|
216
|
+
**Q: How do I make words fit in a specific area?**
|
|
217
|
+
A: Reduce `base_font_size` until the generated canvas is the desired size.
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
**Made with ❤️ for accurate data visualization**
|