Much better than hexbins plots! Use any kind of tile to visualize data and pictures!
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file crazybin-1.0.0.tar.gz.
File metadata
- Download URL: crazybin-1.0.0.tar.gz
- Upload date:
- Size: 17.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9585d9c42342225e885b5d6be337d0b77c143b543e8a57bcf30d4684322ba6f4
|
|
| MD5 |
62c7a5b620ec975992573255a3b55447
|
|
| BLAKE2b-256 |
d43beef20ff8cde9f5405a5ab23c1fa9531444387e408350026808c6ac41639f
|
File details
Details for the file crazybin-1.0.0-py3-none-any.whl.
File metadata
- Download URL: crazybin-1.0.0-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78ba43a32441d52f36e3d2da1bde2d9de19a429e349a7f3bd4281826bc164e02
|
|
| MD5 |
3a6ca576172a75213f31ab1abfb23fe5
|
|
| BLAKE2b-256 |
47b1ee598098009658632efb3f0eaf769acccc094c080982e22a89bc24340935
|