# plot: BZ plots, color models, and fatbands¶

class `elphmod.plot.``Color`(A, B, C, model='RGB')

Representation of a color.

Colors can be defined using different models:

RGB (red, green, blue):

The three RGB channels take values from 0 to 255.

HSV (hue, saturation, value):

The hue is the color angle in degrees from 0 to 360. Values of 0, 120, and 240 correspond to red, green, and blue. The saturation takes values from -1 to 1. A value of 0 is white; negative values yield complementary colors. The value is the RGB amplitude from 0 to 255. A value of 0 is black.

PSV (phase, shift, value):

Superposition of shifted RGB “waves”. The phase and the phase shift from R to G (G to B) are in radians. The value is the amplitude of the wave from 0 to 255.

Colors can be mixed:

```red = Color(255, 0, 0, 'RGB')
green = Color(120, 1, 255, 'HSV')
yellow = (red + green) / 2
```

Here, colors of different models are converted to RGB first.

`elphmod.plot.``HSV2RGB`(H, S=1, V=255)

Transform hue, saturation, value to red, green, blue.

`elphmod.plot.``PSV2RGB`(P, S=1, V=255)

Set color via phase, shift, and value.

`elphmod.plot.``RGB2HSV`(R, G, B)

Transform red, green, blue to hue, saturation, value.

`elphmod.plot.``choose_backend`()

Switch to non-GUI Matplotlib backend if necessary.

`elphmod.plot.``colorbar`(image, left=0.02, bottom=0.02, width=0.03, height=0.3, minimum=None, maximum=None)

`elphmod.plot.``colormap`(*args)

Map interval [0, 1] to colors.

Colors can be defined for an arbitrary number of points in the interval. In between, colors are interpolated linearly. The color for the point `None` is used for NaNs and beyond the outmost points where colors have been defined.

Examples:

```bluebrown = colormap( # PRB 101, 155107 (2020)
(0, Color(0.0, 1, 255, 'PSV'), np.sqrt),
(1, Color(5.5, 1, 255, 'PSV')),
(None, Color(255, 255, 255, 'RGB')),
)

AFMhot = colormap( # Gnuplot
(0.00, Color(  0,   0,   0)),
(0.25, Color(128,   0,   0)),
(0.50, Color(255, 128,   0)),
(0.75, Color(255, 255, 128)),
(1.00, Color(255, 255, 255)),
)
```
`elphmod.plot.``compline`(x, y, composition, center=True)

Plot composition along line.

`elphmod.plot.``double_plot`(mesh, q, nq, qxmin=-0.8, qxmax=0.8, qymin=-0.8, qymax=0.8, resolution=500, interpolation=<function linear_interpolation>, angle=60, outside=0.0, broadcast=True)

Show f(q1, q2, k1, k2) on “Brillouin zone made of Brillouin zones”.

`elphmod.plot.``double_plot_tex`(texfile, imgfile, q, nq, angle=60, qxmin=- 0.8, qxmax=0.8, qymin=- 0.8, qymax=0.8, scale=10.0)

Draw outlines of mini Brillouin zones.

`elphmod.plot.``label_pie_with_TeX`(stem, width=7.0, preamble='\\usepackage[math]{iwona}', width_L=5.0, width_R=1.0, width_C=0.5, spacing=0.5, spacing_T=0.7, title=None, label=None, labels=['Label 1', 'Label 2', 'Label 3', 'Label 4', 'Label 5', 'Label 6'], upper=1.0, lower=-1.0, ticks=[-1.0, 0.0, 1.0], form=<function <lambda>>, unit='Unit', nCDW=10, standalone=True)

Label ‘pie diagram’ of different data on Brillouin zone.

`elphmod.plot.``load`(filename)

Load grayscale, RGB, or RGBA image from 8-bit PNG.

Parameters
filenamestr

Name of PNG file to be written.

Returns
ndarray

8-bit image data of shape (height, width, colors), where colors may be 1 (grayscale), 3 (RGB), or 4 (RGBA).

`elphmod.plot.``plot`(mesh, kxmin=-1.0, kxmax=1.0, kymin=-1.0, kymax=1.0, resolution=100, interpolation=<function linear_interpolation>, angle=60, return_k=False, broadcast=True)

Plot in cartesian reciprocal coordinates.

`elphmod.plot.``plot_pie_with_TeX`(filename, data, points=1000, angle=60, standalone=True, pdf=False, colormap=None, **kwargs)

Create ‘pie diagram’ of different data on Brillouin zone.

`elphmod.plot.``rectify`(image, width, height, lt, rt, lb, rb, *args, **kwargs)

Map skew image selection onto rectangular area.

This function could turn a photograph of a document and its surroundings, taken at any unfortunate angle, into a rectangular image of the document content alone (similar to common scan applications).

Parameters
imagendarray

2D array with image data.

widthfloat

Output width in units of original image width.

heightfloat

Output height in units of original image height.

lttuple of float

Upper-left corner of rectangle as original image coordinates.

rttuple of float

Upper-right corner of rectangle as original image coordinates.

lbtuple of float

Lower-left corner of rectangle as original image coordinates.

rbtuple of float

Lower-right corner of rectangle as original image coordinates.

*args, **kwargs

Arguments passed to linear-interpolation routine.

Returns
ndarray

Rectangular view of image selection.

`elphmod.plot.``save`(filename, image)

Save grayscale, RGB, or RGBA image as 8-bit PNG.

Specified at https://www.w3.org/TR/PNG/. Inspired by Blender thumbnailer code.

Parameters
filenamestr

Name of PNG file to be written.

imagendarray

8-bit image data of shape (height, width, colors), where colors may be 1 (grayscale), 3 (RGB), or 4 (RGBA).

`elphmod.plot.``toBZ`(data=None, points=1000, interpolation=<function linear_interpolation>, angle=120, angle0=0, outside=0.0, return_k=False, return_only_k=False, even=False, broadcast=True)

Map data on uniform grid onto (wedge of) Brillouin zone.

Parameters
angleinteger

Angle between first and second Bravais-lattice vector in degrees.

angle0float

Angle between x axis and first Bravais-lattice vector in degrees.