-
Notifications
You must be signed in to change notification settings - Fork 18
Home
alexkaz2 edited this page Oct 21, 2020
·
4 revisions
6D67 The grid creation and plotting is available through a single function create_hex_grid()
Here is a minimal usage to create the hexagonal grid of about 10x10 hexagons, without plotting it:
from hexalattice.hexalattice import *
hex_centers, _ = create_hex_grid(n=100)
centers_x = hex_centers[:, 0]
centers_x = hex_centers[:, 1]
Add the argument do_plot=True to plot the produced grid
import hexalattice
hex_centers, _ = create_hex_grid(n=100, do_plot=True)
centers_x = hex_centers[:, 0]
centers_x = hex_centers[:, 1]
Here is a full list of parameters with their default values:
hex_centers, h_ax = create_hex_grid(
nx = 4, # Number of horizontal hexagons in rectangular grid, [nx * ny]
ny = 5, # Number of vertical hexagons in rectangular grid, [nx * ny]
min_diam = 1., # Minimal diameter of each hexagon.
n = 0, # Alternative way to create rectangular grid. The final grid might have less hexagons
align_to_origin = True, # Shift the grid s.t. the central tile will center at the origin
face_color = None, # Provide RGB triplet, valid abbreviation (e.g. 'k') or RGB+alpha
edge_color = 'k', # Provide RGB triplet, valid abbreviation (e.g. 'k') or RGB+alpha
plotting_gap = 0., # Gap between the edges of adjacent tiles, in fraction of min_diam
crop_circ = 0., # Disabled if 0. If >0 a circle of central tiles will be kept, with radius r=crop_circ
do_plot = False, # Add the hexagon to an axes. If h_ax not provided a new figure will be opened.
rotate_deg = 0., # Rotate the grid around the center of the central tile, by rotate_deg degrees
h_ax = None # Handle to axes. If provided the grid will be added to it, if not a new figure will be opened.
)
hex_centers, h_ax = create_hex_grid(...)
hex_centers # np.array of shape [H, 2], where H is the number of hexagons in the grid. Every
row hold the [x, y] coordinates of the hexagon.
h_ax # Handle to the matplotlib.axes on to of which the grid was plotted. If 'do_plot=False' it will hold 'None'.
Remarks:
- Minimal diameter is the distance between the centers of two opposite edges.