crazybin


Namecrazybin JSON
Version 1.0.0 PyPI version JSON
download
home_pageNone
SummaryMuch better than hexbins plots! Use any kind of tile to visualize data and pictures!
upload_time2024-05-03 21:52:09
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords hexbin histogram tiling parquet escher
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Crazybin

You think [hexbin](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hexbin.html) 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](https://en.wikipedia.org/wiki/Reptiles_(M._C._Escher)) by [M. C. Escher](https://en.wikipedia.org/wiki/M._C._Escher)?

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

![](examples/images/reptiles_sinewave.jpg)

Crazybin provides two top-level methods: `crazybin` is the counterpart of [matplotlib.hexbin](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hexbin.html). `imshow` is similar to [matplotlib.imshow](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imshow.html). For example, with `imshow`, you can easily turn [Pointillism](https://en.wikipedia.org/wiki/Pointillism) into 'Hexillism'!

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

![](examples/images/grande_jatte_seurat.jpg)

## 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](./examples/).
```python
from crazybin import crazybin, imshow
```
Crazybin can also be used in an object oriented style. See [Custom Tiles](#tile-object).

## 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.
<details>
  <summary>Example JSON for a hexagon</summary>

```json
{
    "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
            ]
        ]
    ]
}
```
</details>


JSON files can be specified by providing a filename with `.json` extension to the tile keyword arguments.
```python
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. 
```python
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](https://preshing.com/20110831/penrose-tiling-explained/). The "reptile" and "frog" patterns were inspired by [this](https://www.geogebra.org/m/CUdKaHeC#material/vnb3vpsy) and [this](https://www.geogebra.org/m/CUdKaHeC#material/pzjk5fru) [Geogebra tesselation projects](https://www.geogebra.org/m/CUdKaHeC). Artist images were taken from Wikipedia.

<img src="https://github.com/Ockenfuss/crazybin/blob/main/examples/images/frogs_gaussian.jpg" width="30%"></img> <img src="https://github.com/Ockenfuss/crazybin/blob/main/examples/images/hex_rhomb.jpg" width="30%"></img> <img src="https://github.com/Ockenfuss/crazybin/blob/main/examples/images/great_wave.jpg" width="30%"></img>

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "crazybin",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "hexbin, histogram, tiling, parquet, escher",
    "author": null,
    "author_email": "Paul Ockenfu\u00df <paul.ockenfuss@physik.uni-muenchen.de>",
    "download_url": "https://files.pythonhosted.org/packages/d4/3b/eef20ff8cde9f5405a5ab23c1fa9531444387e408350026808c6ac41639f/crazybin-1.0.0.tar.gz",
    "platform": null,
    "description": "# Crazybin\n\nYou think [hexbin](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hexbin.html) 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!\n\nWant an example? What about this double sine distribution visualized in the form of [reptiles](https://en.wikipedia.org/wiki/Reptiles_(M._C._Escher)) by [M. C. Escher](https://en.wikipedia.org/wiki/M._C._Escher)?\n\n```python\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom crazybin import crazybin\n\nx=np.linspace(0,10,100)\ny=np.linspace(0,10,100)\nx,y=np.meshgrid(x,y)\nx=x.ravel()\ny=y.ravel()\nweights=np.sin(x)*np.cos(y)\n\ncrazybin(x,y,weights, tile='reptile', cmap='jet', gridsize=4, edgecolor='black')\nplt.show()\n```\n\n![](examples/images/reptiles_sinewave.jpg)\n\nCrazybin provides two top-level methods: `crazybin` is the counterpart of [matplotlib.hexbin](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.hexbin.html). `imshow` is similar to [matplotlib.imshow](https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.imshow.html). For example, with `imshow`, you can easily turn [Pointillism](https://en.wikipedia.org/wiki/Pointillism) into 'Hexillism'!\n\n```python\nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom crazybin import imshow\n\nimage=plt.imread('images/grande_jatte_seurat.jpg')/255\nimshow(image, tile='hex', gridsize=150)\nplt.show()\n```\n\n![](examples/images/grande_jatte_seurat.jpg)\n\n## Usage\n`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](./examples/).\n```python\nfrom crazybin import crazybin, imshow\n```\nCrazybin can also be used in an object oriented style. See [Custom Tiles](#tile-object).\n\n## Tiles\nPossible keywords for the `tile` argument are:\n### Regular Tiles\n- \"hex\": Regular hexagon\n- \"hex_rhomb\": Composition of a regular hexagon, triangles and rhombs/squares.\n- \"reptile\": Composition of three lizard shaped tiles inspired by M.C. Escher\n- \"frog\": Composition of four frog shaped tiles inspired by M.C. Escher.\n\n### Irregular Tiles\n- \"pen_rhomb\": P3 penrose tiling, consisting of two rhombs with different angles.\n\n### Custom Tiles\n#### Via JSON File\nRegular 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.\n<details>\n  <summary>Example JSON for a hexagon</summary>\n\n```json\n{\n    \"v1\": [\n        1.5000000000000002,\n        0.8660254037844379\n    ],\n    \"v2\": [\n        5.551115123125783e-17,\n        1.7320508075688774\n    ],\n    \"atoms\": [\n        [\n            [\n                -0.49999999999999994,\n                0.8660254037844387\n            ],\n            [\n                -1.0,\n                2.1460752085336256e-16\n            ],\n            [\n                -0.5000000000000002,\n                -0.8660254037844385\n            ],\n            [\n                0.49999999999999994,\n                -0.8660254037844387\n            ],\n            [\n                1.0,\n                -6.031855794721673e-16\n            ],\n            [\n                0.5,\n                0.8660254037844387\n            ],\n            [\n                -0.49999999999999994,\n                0.8660254037844387\n            ]\n        ]\n    ]\n}\n```\n</details>\n\n\nJSON files can be specified by providing a filename with `.json` extension to the tile keyword arguments.\n```python\nimshow(image, tile='path/to/hex.json', gridsize=150)\n```\n\n#### Tile Object\nGrids 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. \n```python\nimport numpy as np\nfrom shapely import Polygon\nimport matplotlib.pyplot as plt\nfrom crazybin import Tile, Grid, TileImage, RegularParquetFactory\ngrid=Grid([0,1],[1,0])\ntile=Tile([Polygon([(0,0), (1,0), (1,1), (0,1)])])\nfac=RegularParquetFactory(tile, grid)\nimage=np.random.rand(10,10)\nim=TileImage(image, fac, gridsize=10)\nim.plot()\nplt.show()\n```\n\n## Credits\nThe implementation of the penrose tiling generator was inspired by [this blog article](https://preshing.com/20110831/penrose-tiling-explained/). The \"reptile\" and \"frog\" patterns were inspired by [this](https://www.geogebra.org/m/CUdKaHeC#material/vnb3vpsy) and [this](https://www.geogebra.org/m/CUdKaHeC#material/pzjk5fru) [Geogebra tesselation projects](https://www.geogebra.org/m/CUdKaHeC). Artist images were taken from Wikipedia.\n\n<img src=\"https://github.com/Ockenfuss/crazybin/blob/main/examples/images/frogs_gaussian.jpg\" width=\"30%\"></img> <img src=\"https://github.com/Ockenfuss/crazybin/blob/main/examples/images/hex_rhomb.jpg\" width=\"30%\"></img> <img src=\"https://github.com/Ockenfuss/crazybin/blob/main/examples/images/great_wave.jpg\" width=\"30%\"></img>\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Much better than hexbins plots! Use any kind of tile to visualize data and pictures!",
    "version": "1.0.0",
    "project_urls": {
        "Homepage": "https://github.com/Ockenfuss/crazybin"
    },
    "split_keywords": [
        "hexbin",
        " histogram",
        " tiling",
        " parquet",
        " escher"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "47b1ee598098009658632efb3f0eaf769acccc094c080982e22a89bc24340935",
                "md5": "3a6ca576172a75213f31ab1abfb23fe5",
                "sha256": "78ba43a32441d52f36e3d2da1bde2d9de19a429e349a7f3bd4281826bc164e02"
            },
            "downloads": -1,
            "filename": "crazybin-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3a6ca576172a75213f31ab1abfb23fe5",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 16263,
            "upload_time": "2024-05-03T21:52:07",
            "upload_time_iso_8601": "2024-05-03T21:52:07.267718Z",
            "url": "https://files.pythonhosted.org/packages/47/b1/ee598098009658632efb3f0eaf769acccc094c080982e22a89bc24340935/crazybin-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d43beef20ff8cde9f5405a5ab23c1fa9531444387e408350026808c6ac41639f",
                "md5": "62c7a5b620ec975992573255a3b55447",
                "sha256": "9585d9c42342225e885b5d6be337d0b77c143b543e8a57bcf30d4684322ba6f4"
            },
            "downloads": -1,
            "filename": "crazybin-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "62c7a5b620ec975992573255a3b55447",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 17846,
            "upload_time": "2024-05-03T21:52:09",
            "upload_time_iso_8601": "2024-05-03T21:52:09.045295Z",
            "url": "https://files.pythonhosted.org/packages/d4/3b/eef20ff8cde9f5405a5ab23c1fa9531444387e408350026808c6ac41639f/crazybin-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-03 21:52:09",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Ockenfuss",
    "github_project": "crazybin",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "crazybin"
}
        
Elapsed time: 0.22287s