Skip to content

Much better than hexbins plots! Use any kind of tile to visualize data and pictures!

Notifications You must be signed in to change notification settings

Ockenfuss/crazybin

Repository files navigation

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()

See this interactive demo to create tessellations of your own images.

Installation

The package can be installed using pip:

pip install crazybin

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.

About

Much better than hexbins plots! Use any kind of tile to visualize data and pictures!

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages