https://github.com/precondition/hot_blobs
A Python library for drawing transparent heatmap overlays
https://github.com/precondition/hot_blobs
data-viz heatmap python python3
Last synced: about 2 months ago
JSON representation
A Python library for drawing transparent heatmap overlays
- Host: GitHub
- URL: https://github.com/precondition/hot_blobs
- Owner: precondition
- License: bsd-3-clause-clear
- Created: 2021-11-27T19:52:50.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-11-27T19:59:51.000Z (over 4 years ago)
- Last Synced: 2025-01-27T22:13:58.616Z (over 1 year ago)
- Topics: data-viz, heatmap, python, python3
- Language: Python
- Homepage:
- Size: 38.1 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Hot Blobs
A Python library for drawing heatmap overlays with the same look and feel as
[simpleheat](https://github.com/mourner/simpleheat) and [heatmap.js](https://github.com/pa7/heatmap.js).
![Glamor shot]()
A "heatmap" can take many forms but this library focuses only on a single kind. See the illustrated table below.
Geographic zoomable maps are not supported.
![Horizontal strip of different heatmap types with a red cross in the corner of unsupported heatmap types]()
## Reference
### Constructor
| Constructor | Description |
|-------------|-------------|
| `Heatmap(w: int, h: int)` | Constructs an empty `Heatmap` of dimensions `w`×`h` |
### Public Methods
| Return type | Method | Description |
|-------------|--------|-------------|
| hot_blobs.Heatmap | `data(data: Iterable[Tuple[int]], compute_max: bool = True)` | Initialise the heatmap data with `data` |
| hot_blobs.Heatmap | `add(data: Iterable[Tuple[int, int]]` | Adds one or more data points to the heatmap |
| hot_blobs.Heatmap | `clear()` | Clears all heatmap data points. |
| hot_blobs.Heatmap | `max(maximum: int)` | Sets the maximum value with which to normalise the heatmap data points. |
| hot_blobs.Heatmap | `stamp(r: int = 25, blur: int = 51)` | Creates a grayscale blurred circle image used like a rubber stamp for drawing points. |
| hot_blobs.Heatmap | `resize(w: int, h: int)` | Resizes the dimensions of the heatmap. |
| hot_blobs.Heatmap | `gradient(grad: Dict[float, Union[str, QColor]])` | Sets the color gradient to use in the heatmap to `grad`. |
| np.ndarray | `generate_image(min_opacity: float = 0.05)` | Generates the final heatmap image in the form of a `width`×`height`×4 numpy array in RGBA format. |
Each method contains a detailed docstring that you can consult anytime by typing `help(Heatmap.method_name)`.
The reason why all those "setter" methods return an instance of the Heatmap object is for purposes of function chaining.
This means that these two code blocks are perfectly equivalent:
```py
from hot_blobs import Heatmap
hm = Heatmap(600, 300)
hm.data(my_data)
hm.max(20)
hm.stamp(r=10, blur=63)
im = hm.generate_image(0.1)
```
```py
from hot_blobs import Heatmap
im = Heatmap(600, 300).data(my_data).max(20).stamp(r=10, blur=63).generate_image(0.1)
```
### Basic example
```py
import hot_blobs
from PIL import Image # Use any desired library to convert the RGBA matrix into an image
# You can either feed in a collection of non-unique 2D tuples
# or a dictionary that associates a value to each unique tuple.
observations = [(400, 300), (400, 300), (400, 300), (10, 20), (10, 20), (750, 530)]
observations = {(400, 300): 3, (10, 20): 2, (750, 530): 1}
heatmap_obj = hot_blobs.Heatmap(w=800, h=600).data(observations)
heatmap_matrix = heatmap_obj.generate_image()
Image.fromarray(heatmap_matrix).save("basic_heatmap_example.png")
```
See the `demo/` directory for more examples.