Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
 
 

Latest commit

 

History

46 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Repository Archived

Notice of Archive

This fork has been archived. The modifications made in this fork is no longer required due to updates in the main repository. For ongoing development and the latest version, please refer to the original project.

This repository is retained for historical reference and may be useful for those with dependencies on its specific modifications.

Changes Made

This repository is a fork of the original repository

Changes Made

  • add encoding="utf-8" in line 8 of setup.py.
  • Commented out matplotlib.use('Qt5Agg') in line 17 of hexalattice.py.

hexalattice

Generate and plot hexagonal lattices in 2D, with fine control over spacing between hexagons, arbitrary rotation of the grid around central tile, etc. The module computes and returns the center point for each of the tiles in the lattice.

Installation

PyPI version conda python version downloads_anaconda license last updated

# Using pip
pip install hexalattice
# Using conda
conda install -c conda-forge hexalattice

Usage example

Create and plot 5x5 lattice of hexagons (as in first image):

from hexalattice.hexalattice import *
hex_centers, _ = create_hex_grid(nx=5,
                                 ny=5,
                                 do_plot=True)
                                 
plt.show()    # import matplotlib.pyplot as plt

Get central points of the hexagons:

tile_centers_x = hex_centers[:, 0]
tile_centers_y = hex_centers[:, 1]

Plot one grid over the other, second with spacing around the hexagons:

_, h_ax = create_hex_grid(nx=5, 
                          ny=7,
                          do_plot=True,
                          edge_color=(0.85, 0.85, 0.85))
                                    
create_hex_grid(nx=5,
                ny=7,
                do_plot=True,
                edge_color=(0.25,0.25, 0.25),
                h_ax=h_ax,
                plotting_gap=0.3)
plt.show()

Create Moiré pattern from two circularly cropped hexagrids:

hex_grid1, h_ax = create_hex_grid(nx=50,
                                  ny=50,
                                  rotate_deg=0,
                                  min_diam=1,
                                  crop_circ=20,
                                  do_plot=True)
    create_hex_grid(nx=50,
                    ny=50,
                    min_diam=1,
                    rotate_deg=5,
                    crop_circ=20,
                    do_plot=True,
                    h_ax=h_ax)

For API and additional examples see the wiki hexalattice API and assigning individual colors to hexagons.

Release History

  • v1.0.0 - First version
  • v1.1.0 - Added the option to assign different colors to hexagons
  • v1.2.0 - Added control over the outer line width of the hexagons
  • v1.2.2 - Added control over the axis background color

About & License

Alex Kazakov – @bio_vs_silicoalex.kazakov@mail.huji.ac.il

Distributed under the MIT license. See LICENSE for more information.

https://github.com/alexkaz2/hexalattice

About

Create and plot hexagonal lattices

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages