Crazybin
You think hexbin plots are a fancy way to visualize your data? Well, you can go much further... Check out Crazybin to bring your histograms to a whole new level!
Want an example? What about this double sine distribution visualized in the form of reptiles by M. C. Escher?
import numpy as np
import matplotlib.pyplot as plt
from crazybin import crazybin
x=np.linspace(0,10,100)
y=np.linspace(0,10,100)
x,y=np.meshgrid(x,y)
x=x.ravel()
y=y.ravel()
weights=np.sin(x)*np.cos(y)
crazybin(x,y,weights, tile='reptile', cmap='jet', gridsize=4, edgecolor='black')
plt.show()
Crazybin provides two top-level methods: crazybin is the counterpart of matplotlib.hexbin. imshow is similar to matplotlib.imshow. For example, with imshow, you can easily turn Pointillism into 'Hexillism'!
import numpy as np
import matplotlib.pyplot as plt
from crazybin import imshow
image=plt.imread('images/grande_jatte_seurat.jpg')/255
imshow(image, tile='hex', gridsize=150)
plt.show()
Usage
crazybin and imshow are (more or less) drop-in replacements of matplotlib.hexbin and matplotlib.imshow. For detailed information, check out their doc-strings. See also the examples in the examples folder.
from crazybin import crazybin, imshow
Crazybin can also be used in an object oriented style. See Custom Tiles.
Tiles
Possible keywords for the tile argument are:
Regular Tiles
- "hex": Regular hexagon
- "hex_rhomb": Composition of a regular hexagon, triangles and rhombs/squares.
- "reptile": Composition of three lizard shaped tiles inspired by M.C. Escher
- "frog": Composition of four frog shaped tiles inspired by M.C. Escher.
Irregular Tiles
- "pen_rhomb": P3 penrose tiling, consisting of two rhombs with different angles.
Custom Tiles
Via JSON File
Regular tiles can be read from files with json format. v1 and v2 contain the lattice vectors, defining the translation directions of the tiles. Each tile consists of one or more 'atoms', which are arbitrary shapes which make up the tile.
Example JSON for a hexagon
{
"v1": [
1.5000000000000002,
0.8660254037844379
],
"v2": [
5.551115123125783e-17,
1.7320508075688774
],
"atoms": [
[
[
-0.49999999999999994,
0.8660254037844387
],
[
-1.0,
2.1460752085336256e-16
],
[
-0.5000000000000002,
-0.8660254037844385
],
[
0.49999999999999994,
-0.8660254037844387
],
[
1.0,
-6.031855794721673e-16
],
[
0.5,
0.8660254037844387
],
[
-0.49999999999999994,
0.8660254037844387
]
]
]
}
JSON files can be specified by providing a filename with .json extension to the tile keyword arguments.
imshow(image, tile='path/to/hex.json', gridsize=150)
Tile Object
Grids consist of Tile objects, which can be instantiated from a list of shapely.Polygon objects. For a regular parquet, you need to specify two grid vectors via a Grid object, defining the translations of the tiles.
import numpy as np
from shapely import Polygon
import matplotlib.pyplot as plt
from crazybin import Tile, Grid, TileImage, RegularParquetFactory
grid=Grid([0,1],[1,0])
tile=Tile([Polygon([(0,0), (1,0), (1,1), (0,1)])])
fac=RegularParquetFactory(tile, grid)
image=np.random.rand(10,10)
im=TileImage(image, fac, gridsize=10)
im.plot()
plt.show()
Credits
The implementation of the penrose tiling generator was inspired by this blog article. The "reptile" and "frog" patterns were inspired by this and this Geogebra tesselation projects. Artist images were taken from Wikipedia.
Metadata
Release files for crazybin 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| crazybin-1.0.0.tar.gz | 17.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| crazybin-1.0.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 34.1 kB
Release files / crazybin-1.0.0.tar.gz
| Download URL | crazybin-1.0.0.tar.gz |
|---|---|
| Size | 17.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9585d9c42342225e885b5d6be337d0b77c143b543e8a57bcf30d4684322ba6f4
|
|
BLAKE2b-256 checksum How to use checksums |
d43beef20ff8cde9f5405a5ab23c1fa9531444387e408350026808c6ac41639f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.10.12
|
Release files / crazybin-1.0.0-py3-none-any.whl
| Download URL | crazybin-1.0.0-py3-none-any.whl |
|---|---|
| Size | 16.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
78ba43a32441d52f36e3d2da1bde2d9de19a429e349a7f3bd4281826bc164e02
|
|
BLAKE2b-256 checksum How to use checksums |
47b1ee598098009658632efb3f0eaf769acccc094c080982e22a89bc24340935
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.0.0 CPython/3.10.12
|