erlab.plotting.atoms

Plot atoms.

Classes and functions for plotting atoms and bonds in a crystal structure using matplotlib’s 3D plotting capabilities.

Some of the projection code was adapted from kwant.

Functions

projected_length(ax, length)

projected_length_pos(ax, length, position)

sunflower_sphere([n])

Return n points on a sphere using the sunflower algorithm.

Classes

Atom3DCollection(*args[, scale_size])

A collection of 3D scatter points that represents atoms in a crystal structure.

Bond3DCollection(segments, *[, scale_linewidths])

A collection of 3D lines that represents bonds in a crystal structure.

CrystalProperty(atom_pos, avec[, offset, ...])

class erlab.plotting.atoms.Atom3DCollection(*args, scale_size=True, **kwargs)[source]

Bases: Path3DCollection

A collection of 3D scatter points that represents atoms in a crystal structure.

This class is not for direct instantiation, but is used to patch the collection returned by the scatter method. See the implementation of CrystalProperty.plot for usage.

draw(renderer)[source]
set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, antialiased=<UNSET>, array=<UNSET>, capstyle=<UNSET>, clim=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, cmap=<UNSET>, color=<UNSET>, depthshade=<UNSET>, edgecolor=<UNSET>, facecolor=<UNSET>, gid=<UNSET>, hatch=<UNSET>, in_layout=<UNSET>, joinstyle=<UNSET>, label=<UNSET>, linestyle=<UNSET>, linewidth=<UNSET>, mouseover=<UNSET>, norm=<UNSET>, offset_transform=<UNSET>, offsets=<UNSET>, path_effects=<UNSET>, paths=<UNSET>, picker=<UNSET>, pickradius=<UNSET>, rasterized=<UNSET>, sizes=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, sort_zpos=<UNSET>, transform=<UNSET>, url=<UNSET>, urls=<UNSET>, visible=<UNSET>, zorder=<UNSET>)[source]

Set multiple properties at once.

Supported properties are

Properties:

3d_properties: float or array of floats agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image alpha: array-like or scalar or None animated: bool antialiased or aa or antialiaseds: bool or list of bools array: array-like or None capstyle: CapStyle or {‘butt’, ‘projecting’, ‘round’} clim: (vmin: float, vmax: float) clip_box: BboxBase or None clip_on: bool clip_path: Patch or (Path, Transform) or None cmap: Colormap or str or None color: :mpltype:`color` or list of RGBA tuples depthshade: bool edgecolor or ec or edgecolors: :mpltype:`color` or list of :mpltype:`color` or ‘face’ facecolor or facecolors or fc: :mpltype:`color` or list of :mpltype:`color` figure: Figure gid: str hatch: {‘/’, ‘\’, ‘|’, ‘-’, ‘+’, ‘x’, ‘o’, ‘O’, ‘.’, ‘*’} in_layout: bool joinstyle: JoinStyle or {‘miter’, ‘round’, ‘bevel’} label: object linestyle or dashes or linestyles or ls: str or tuple or list thereof linewidth or linewidths or lw: float or list of floats mouseover: bool norm: Normalize or str or None offset_transform or transOffset: Transform offsets: (N, 2) or (2,) array-like path_effects: list of AbstractPathEffect paths: unknown picker: None or bool or float or callable pickradius: float rasterized: bool sizes: unknown sketch_params: (scale: float, length: float, randomness: float) snap: bool or None sort_zpos: unknown transform: Transform url: str urls: list of str or None visible: bool zorder: float

set_sizes(sizes, dpi=72.0)[source]
class erlab.plotting.atoms.Bond3DCollection(segments, *, scale_linewidths=True, **kwargs)[source]

Bases: Line3DCollection

A collection of 3D lines that represents bonds in a crystal structure.

Parameters:
  • segments – List of segments representing the bonds.

  • scale_linewidths (bool) – Boolean indicating whether to scale the linewidths based on the plot’s perspective.

  • **kwargs – Additional keyword arguments to be passed to mpl_toolkits.mplot3d.art3d.Line3DCollection.

draw(renderer)[source]
set(*, agg_filter=<UNSET>, alpha=<UNSET>, animated=<UNSET>, antialiased=<UNSET>, array=<UNSET>, capstyle=<UNSET>, clim=<UNSET>, clip_box=<UNSET>, clip_on=<UNSET>, clip_path=<UNSET>, cmap=<UNSET>, color=<UNSET>, colors=<UNSET>, edgecolor=<UNSET>, facecolor=<UNSET>, gapcolor=<UNSET>, gid=<UNSET>, hatch=<UNSET>, in_layout=<UNSET>, joinstyle=<UNSET>, label=<UNSET>, linestyle=<UNSET>, linewidth=<UNSET>, mouseover=<UNSET>, norm=<UNSET>, offset_transform=<UNSET>, offsets=<UNSET>, path_effects=<UNSET>, paths=<UNSET>, picker=<UNSET>, pickradius=<UNSET>, rasterized=<UNSET>, segments=<UNSET>, sketch_params=<UNSET>, snap=<UNSET>, sort_zpos=<UNSET>, transform=<UNSET>, url=<UNSET>, urls=<UNSET>, verts=<UNSET>, visible=<UNSET>, zorder=<UNSET>)[source]

Set multiple properties at once.

Supported properties are

Properties:

agg_filter: a filter function, which takes a (m, n, 3) float array and a dpi value, and returns a (m, n, 3) array and two offsets from the bottom left corner of the image alpha: array-like or scalar or None animated: bool antialiased or aa or antialiaseds: bool or list of bools array: array-like or None capstyle: CapStyle or {‘butt’, ‘projecting’, ‘round’} clim: (vmin: float, vmax: float) clip_box: BboxBase or None clip_on: bool clip_path: Patch or (Path, Transform) or None cmap: Colormap or str or None color: :mpltype:`color` or list of :mpltype:`color` colors: :mpltype:`color` or list of :mpltype:`color` edgecolor or ec or edgecolors: :mpltype:`color` or list of :mpltype:`color` or ‘face’ facecolor or facecolors or fc: :mpltype:`color` or list of :mpltype:`color` figure: Figure gapcolor: :mpltype:`color` or list of :mpltype:`color` or None gid: str hatch: {‘/’, ‘\’, ‘|’, ‘-’, ‘+’, ‘x’, ‘o’, ‘O’, ‘.’, ‘*’} in_layout: bool joinstyle: JoinStyle or {‘miter’, ‘round’, ‘bevel’} label: object linestyle or dashes or linestyles or ls: str or tuple or list thereof linewidth or linewidths or lw: unknown mouseover: bool norm: Normalize or str or None offset_transform or transOffset: Transform offsets: (N, 2) or (2,) array-like path_effects: list of AbstractPathEffect paths: unknown picker: None or bool or float or callable pickradius: float rasterized: bool segments: unknown sketch_params: (scale: float, length: float, randomness: float) snap: bool or None sort_zpos: unknown transform: Transform url: str urls: list of str or None verts: unknown visible: bool zorder: float

set_linewidth(lw)[source]
class erlab.plotting.atoms.CrystalProperty(atom_pos, avec, offset=(0.0, 0.0, 0.0), radii=None, colors=None, repeat=(1, 1, 1), bounds=None, mask=None, r_factor=0.4)[source]

Bases: object

add_bonds(atom1, atom2, min_length=0.0, max_length=2.6, linewidth=0.25, color=None)[source]
clear_bonds()[source]
classmethod from_fractional(frac_pos, avec, *args, **kwargs)[source]
plot(ax=None, scale_bonds=True, scale_atoms=True, clean_axes=True, bond_kw=None, atom_kw=None)[source]

Plot the crystal structure.

Parameters:
  • ax (Axes3D | None) – A 3D axes object to plot the crystal on. If not provided, add_subplot will be called on the current figure.

  • scale_bonds (bool) – Whether to scale the bond linewidths based on the distance from the camera, by default True

  • scale_atoms (bool) – Whether to scale the atom sizes based on the distance from the camera, by default True

  • clean_axes (bool) – Whether to clean the axes by removing the background and grid, setting pane color, and removing the margins, by default True

  • bond_kw (dict | None) – Keyword arguments passed onto Bond3DCollection

  • atom_kw (dict | None) – Keyword arguments passed onto mpl_toolkits.mplot3d.Axes3D.scatter used to plot the atoms.

property atom_pos: dict[str, ndarray[Any, dtype[float64]]]
property atoms: list[str]
property bounds: list[tuple[float, float]]