The vis visualization submodule

General empyre.vis docu here!

All functions implemented in the subpackages can be accessed directly in the empyre.io namespace, with the exception of the color module, whose methods are accessible via empyre.vis.colors.

Note that the y-axis of all image plots is flipped in comparison to matplotlib.pyplot.imshow, i.e. that the origin is ‘lower’ in this case instead of ‘upper’.

Please note that 3D plots only work in your Jupyter notebook after first installing and then enabling the corresponding mayavi extension:

$ jupyter nbextension install --py mayavi --user
$ jupyter nbextension enable mayavi --user --py

If you’d like to utilize 3D plots in your Jupyter Notebook or in the Python Interactive Window

>>> from mayavi import mlab
>>> mlab.init_notebook('x3d')

The backend, chosen by the init_notebook function can be ipy (the default, produces static images in Juypter Notebook and does not work in VSCode), x3d (produces interactive plots in Jupyter Noteboo, but seems to not work with VSCode), or png (produces png-images, which work in both Jupyter Notebooks and VSCode). For more information and a quick introduction visit the mayavi tips & tricks section.

The plot2d module

This module provides functions for 2D plots that often wrap functions from maptlotlib.pyplot.

imshow(field, axis=None, cmap=None, **kwargs)[source]

Display an image on a 2D regular raster. Wrapper for matplotlib.pyplot.imshow.

Parameters
fieldField or ndarray

The image data as a Field or a numpy array (in the latter case, vector=False and scale=1.0 are assumed).

axismatplotlib.axes.Axes object, optional

The axis to which the image should be added, by default None, which will pick the last use axis via gca.

cmapstr or matplotlib.colors.Colormap, optional

The Colormap that should be used for the display, either as a string or object, by default None, which will pick cmocean.cm.balance if available. imshow will automatically detect if a divergent colormap is used and will make sure that zero is pinned to the symmetry point of the colormap (this is done by creating a new colormap with custom range under the hood).

Returns
axismatplotlib.axes.Axes

The plotting axis.

Notes

Additional kwargs are passed to imshow(). Note that the y-axis of the plot is flipped in comparison to imshow(), i.e. that the origin is ‘lower’ in this case instead of ‘upper’. Uses the empyre-image stylesheet settings for plotting (and axis creation if none exists, yet). Fields are squeezed before plotting, so non-2D fields work as long as their superfluous dimensions have length 1.

contour(field, axis=None, **kwargs)[source]

Plot contours. Wrapper for matplotlib.pyplot.contour.

Parameters
fieldField or ndarray

The contour data as a Field or a numpy array (in the latter case, vector=False and scale=1.0 are assumed).

axismatplotlib.axes.Axes object, optional

The axis to which the contour should be added, by default None, which will pick the last use axis via gca.

Returns
axismatplotlib.axes.Axes

The plotting axis.

Notes

Additional kwargs are passed to matplotlib.pyplot.contour. Note that the y-axis of the plot is flipped in comparison to imshow(), i.e. that the origin is ‘lower’ in this case instead of ‘upper’. Uses the empyre-image stylesheet settings for plotting (and axis creation if none exists, yet). Fields are squeezed before plotting, so non-2D fields work as long as their superfluous dimensions have length 1.

colorvec(field, axis=None, **kwargs)[source]

Plot an image of a 2D vector field with up to 3 components by color encoding the vector direction.

In-plane directions are encoded via hue (“color wheel”), making sure that all in-plane directions are isoluminant (i.e. a greyscale image would result a homogeneously medium grey image). Out-of-plane directions are encoded via brightness with upwards pointing vectors being white and downward pointing vectors being black. The length of the vectors are encoded via saturation, with full saturation being fully chromatic (in-plane) or fully white/black (up/down). The center of the “color sphere” desaturated in a medium gray and encodes vectors with length zero.

Parameters
fieldField or ndarray

The image data as a Field or a numpy array (in the latter case, vector=True and scale=1.0 are assumed).

axismatplotlib.axes.Axes object, optional

The axis to which the image should be added, by default None, which will pick the last use axis via gca.

Returns
axismatplotlib.axes.Axes

The plotting axis.

Notes

Additional kwargs are passed to matplotlib.pyplot.imshow. Note that the y-axis of the plot is flipped in comparison to imshow(), i.e. that the origin is ‘lower’ in this case instead of ‘upper’. Uses the empyre-image stylesheet settings for plotting (and axis creation if none exists, yet). Fields are squeezed before plotting, so non-2D fields work as long as their superfluous dimensions have length 1. Even though squeezing takes place, colorvec “remembers” the original orientation of the slice! This is important if you want to plot a slice that should not represent the xy-plane. The colors chosen will respect the original orientation of your slice, e.g. a vortex in the xz-plane will include black and white colors (up/down) if the Field object given as the field parameter has dim=(128, 1, 128). If you want to plot a slice of a 3D vector with 3 components and make use of this functionality, make sure to not use an integer as an index, as that will drop the dimension BEFORE it is passed to colorvec, which will have no way of knowing which dimension was dropped. Instead, make sure to use a slice of length one (example with dim=(128, 128, 128)): >>> colorvec(field[:, 15, :]) # Wrong! Shape: (128, 128), interpreted as xy-plane! >>> colorvec(field[:, 15:16, :]) # Right! Shape: (128, 1, 128), passed as 3D to colorvec, squeezed internally!

cosine_contours(field, axis=None, gain='auto', cmap=None, **kwargs)[source]

Plots the cosine of the (amplified) field. Wrapper for matplotlib.pyplot.imshow.

Parameters
fieldField or ndarray

The contour data as a Field or a numpy array (in the latter case, vector=False and scale=1.0 are assumed).

axismatplotlib.axes.Axes object, optional

The axis to which the contour should be added, by default None, which will pick the last use axis via gca.

gainfloat or ‘auto’, optional

Gain factor with which the Field is amplified before taking the cosine, by default ‘auto’, which calculates a gain factor that would produce roughly 4 cosine contours.

cmapstr or matplotlib.colors.Colormap, optional

The Colormap that should be used for the display, either as a string or object, by default None, which will pick colors.cmaps[‘transparent_black’] that will alternate between regions with alpha=0, showing layers below and black contours.

Returns
axismatplotlib.axes.Axes

The plotting axis.

Notes

Additional kwargs are passed to matplotlib.pyplot.imshow. Uses the empyre-image stylesheet settings for plotting (and axis creation if none exists, yet). Fields are squeezed before plotting, so non-2D fields work as long as their superfluous dimensions have length 1.

quiver(field, axis=None, color_angles=False, cmap=None, n_bin='auto', bin_with_mask=True, **kwargs)[source]

Plot a 2D field of arrows. Wrapper for matplotlib.pyplot.imshow.

Parameters
fieldField or ndarray

The vector data as a Field or a numpy array (in the latter case, vector=True and scale=1.0 are assumed).

axismatplotlib.axes.Axes object, optional

The axis to which the image should be added, by default None, which will pick the last use axis via gca.

color_anglesbool, optional

Switch that turns on color encoding of the arrows, by default False. Encoding works the same as for the colorvec function (see for details). If False, arrows are uniformly colored white with black border. In both cases, the amplitude is encoded via the transparency of the arrow.

cmapstr or matplotlib.colors.Colormap, optional

The Colormap that should be used for the arrows, either as a string or object, by default None. Will only be used if color_angles=True.

n_binfloat or ‘auto’, optional

Number of entries along each axis over which the average is taken, by default ‘auto’, which automatically determines a bin size resulting in roughly 16 arrows along the largest dimension. Usually sensible to leave this on to not clutter the image with too many arrows (also due to performance). Can be turned off by setting n_bin=1. Uses the ..fields.field.Field.bin method.

bin_with_maskbool, optional

If True (default) and if n_bin>1, entries of the constructed binned Field that averaged over regions that were outside the ..fields.field.Field.mask will not be assigned an arrow and stay empty instead. This prevents errouneous “fade-out” effects of the arrows that would occur even for homogeneous objects.

Returns
quivQuiver instance

The quiver instance that was created.

Notes

Additional kwargs are passed to matplotlib.pyplot.quiver. Uses the empyre-image stylesheet settings for plotting (and axis creation if none exists, yet). Fields are squeezed before plotting, so non-2D fields work as long as their superfluous dimensions have length 1. Even though squeezing takes place, quiver “remembers” the original orientation of the slice and which dimensions were squeezed! See colorvec for more information and an example (the same principles apply here, too). The transparency of the arrows denotes the 3D(!) amplitude, if you see dots in the plot, that means the amplitude is not zero, but simply out of the current plane!

The decorators module

This module provides functions that decorate exisiting matplotlib plots.

scalebar(axis=None, unit='nm', loc='lower left', **kwargs)[source]

Add a scalebar to the axis.

Parameters
axisAxesSubplot, optional

Axis to which the scalebar is added, by default None, which will pick the last used axis via gca.

unit: str, optional

String that determines the unit of the scalebar, defaults to ‘nm’.

locstr or pair of floats, optional

The location of the scalebar, defaults to ‘lower left’. See matplotlib.legend for possible settings.

Returns
aoffboxAnchoredOffsetbox

The box containing the scalebar.

Notes

Additional kwargs are passed to mpl_toolkits.axes_grid1.anchored_artists.AnchoredSizeBar.

colorwheel(axis=None, cmap=None, ax_size='20%', loc='upper right', **kwargs)[source]

Add a colorwheel to the axis on the upper right corner.

Parameters
axisAxes, optional

Axis to which the colorwheel is added, by default None, which will pick the last used axis via gca.

cmapstr or matplotlib.colors.Colormap, optional

The Colormap that should be used for the colorwheel, defaults to None, which chooses the .colors.cmaps.cyclic_cubehelix colormap. Needs to be a Colormap3D to work correctly.

ax_sizestr or float, optional

String or float determining the size of the inset axis used, defaults to 20%.

locstr or pair of floats, optional

The location of the colorwheel, defaults to ‘upper right’. See matplotlib.legend for possible settings.

Returns
axisAxesImage

The colorwheel image that was created.

Notes

Additional kwargs are passed to plot_colorwheel of the Colormap3D.

annotate(label, axis=None, loc='upper left')[source]

Add an annotation to the axis on the upper left corner.

Parameters
labelstring

The text of the annotation.

axisAxesSubplot, optional

Axis to which the annotation is added, by default None, which will pick the last used axis via gca.

locstr or pair of floats, optional

The location of the annotation, defaults to ‘upper left’. See matplotlib.legend for possible settings.

Returns
aoffboxAnchoredOffsetbox

The box containing the annotation.

quiverkey(quiv, field, axis=None, unit='', loc='lower right', **kwargs)[source]

Add a quiver key to an axis.

Parameters
quivQuiver instance

The quiver instance returned by a call to quiver.

fieldField or ndarray

The vector data as a Field or a numpy array (in the latter case, vector=True and scale=1.0 are assumed).

axisAxesSubplot, optional

Axis to which the quiverkey is added, by default None, which will pick the last used axis via gca.

unit: str, optional

String that determines the unit of the quiverkey, defaults to ‘’.

locstr or pair of floats, optional

The location of the quiverkey, defaults to ‘lower right’. See matplotlib.legend for possible settings.

Returns
qk: Quiverkey

The generated quiverkey.

Notes

Additional kwargs are passed to matplotlib.pyplot.quiverkey.

coords(axis=None, coords=('x', 'y'), loc='lower left', **kwargs)[source]

Add coordinate arrows to an axis.

Parameters
axisAxesSubplot, optional

Axis to which the coordinates are added, by default None, which will pick the last used axis via gca.

coordstuple or int, optional

Tuple of strings determining the labels, by default (‘x’, ‘y’). Can also be 2 or 3 which expands to (‘x’, ‘y’) or (‘x’, ‘y’, ‘z’). The length of coords determines the number of arrows (2 or 3).

locstr, optional

[description], by default ‘lower left’

Returns
ins_axesAxes

The created inset axes containing the coordinates.

colorbar(im, fig=None, cbar_axis=None, axes=None, position='right', pad=0.02, thickness=0.03, label=None, constrain_ticklabels=True, ticks=None, ticklabels=None)[source]

Creates a colorbar, aligned with figure axes.

Parameters
immatplotlib object, mappable

Mappable matplotlib object.

figmatplotlib.figure object, optional

The figure object that contains the matplotlib axes and artists, by default None, which will pick the last used figure via gcf.

axesmatplotlib.axes or list of matplotlib.axes

The axes object(s), where the colorbar is drawn, by default None, which will pick the last used axis via gca. Only provide those axes, which the colorbar should span over.

positionstr, optional

The position defines the location of the colorbar. One of ‘top’, ‘bottom’, ‘left’ or ‘right’ (default).

padfloat, optional

Defines the spacing between the axes and colorbar axis. Is given in figure fraction.

thicknessfloat, optional

Thickness of the colorbar given in figure fraction.

labelstring, optional

Colorbar label, defaults to None.

constrain_ticklabelsbool, optional

Allows to slightly shift the outermost ticklabels, such that they do not exceed the cbar axis, defaults to True.

tickslist, np.ndarray, optional

List of cbar ticks, defaults to None.

ticklabelslist, np.ndarray, optional

List of cbar ticklabels, defaults to None.

Returns
cbarColorbar

The created colorbar.

Notes

Based on a modified snippet by Florian Winkler. Note that this function TURNS OFF constrained layout, therefore it should be the final command before finishing or saving a figure. The colorbar will be outside the original bounds of your constructed figure. If you set the size, e.g. with ~empyre.vis.tools.new, make sure to account for the additional space by setting the width_scale to something smaller than 1 (e.g. 0.9).

The colors module

This module provides a number of custom colormaps, which also have capabilities for 3D plotting. If this is the case, the Colormap3D colormap class is a parent class. In cmaps, a number of specialised colormaps is available for convenience. For general questions about colors see: http://www.poynton.com/PDFs/GammaFAQ.pdf http://www.poynton.com/PDFs/ColorFAQ.pdf

class Colormap3D(name, N=256)[source]

Bases: matplotlib.colors.Colormap

Colormap subclass for encoding directions with colors.

This abstract class is used as a superclass/interface for 3D vector plotting capabilities. In general, a circular colormap should be used to encode the in-plane angle (hue). The perpendicular angle is encoded via luminance variation (up: white, down: black). Finally, the length of a vector is encoded via saturation. Decreasing vector length causes a desaturated color. Subclassing colormaps get access to routines to plot a colorwheel (which should ideally be located in the 50% luminance plane, which depends strongly on the underlying map), a convenience function to interpolate color tuples and a function to return rgb triples for a given vector. The Colormap3D class itself subclasses the matplotlib base colormap.

make_colorwheel(self, size=64)[source]

Construct a color wheel as an Image object.

Parameters
sizeint, optional

Diameter of the color wheel along both axes in pixels, by default 64.

Returns
img: Image

The resulting image.

plot_colorwheel(self, axis=None, size=64, arrows=True, grayscale=False, **kwargs)[source]

Display a color wheel to illustrate the color coding of vector gradient directions.

Parameters
figsizetuple of floats (N=2)

Size of the plot figure.

Returns
img: matplotlib.image.AxesImage

The resulting colorwheel.

rgb_from_vector(self, vector, vmax=None)[source]

Construct a hls tuple from three coordinates representing a 3D direction.

Parameters
vector: tuple (N=3) or :class:`~numpy.ndarray`

Vector containing the x, y and z component, or a numpy array encompassing the components as three lists.

Returns
rgb: ndarray

Numpy array containing the calculated color tuples.

class ColormapCubehelix(start=0.5, rot=-1.5, gamma=1.0, reverse=False, nlev=256, minSat=1.2, maxSat=1.2, minLight=0.0, maxLight=1.0, **kwargs)[source]

Bases: matplotlib.colors.LinearSegmentedColormap, empyre.vis.colors.Colormap3D

A full implementation of Dave Green’s “cubehelix” for Matplotlib.

Based on the FORTRAN 77 code provided in D.A. Green, 2011, BASI, 39, 289. http://adsabs.harvard.edu/abs/2011arXiv1108.5083G Also see: http://www.mrao.cam.ac.uk/~dag/CUBEHELIX/ http://davidjohnstone.net/pages/cubehelix-gradient-picker User can adjust all parameters of the cubehelix algorithm. This enables much greater flexibility in choosing color maps. Default color map settings produce the standard cubehelix. Create color map in only blues by setting rot=0 and start=0. Create reverse (white to black) backwards through the rainbow once by setting rot=1 and reverse=True, etc. Furthermore, the algorithm was tuned, so that constant luminance values can be used (e.g. to create a truly isoluminant colorwheel). The rot parameter is also tuned to hold true for these cases. Of the here presented colorwheels, only this one manages to solely navigate through the L*=50 plane, which can be seen here: https://upload.wikimedia.org/wikipedia/commons/2/21/Lab_color_space.png

Parameters
startscalar, optional

Sets the starting position in the color space. 0=blue, 1=red, 2=green. Defaults to 0.5.

rotscalar, optional

The number of rotations through the rainbow. Can be positive or negative, indicating direction of rainbow. Negative values correspond to Blue->Red direction. Defaults to -1.5.

gammascalar, optional

The gamma correction for intensity. Defaults to 1.0.

reverseboolean, optional

Set to True to reverse the color map. Will go from black to white. Good for density plots where shade~density. Defaults to False.

nlevscalar, optional

Defines the number of discrete levels to render colors at. Defaults to 256.

satscalar, optional

The saturation intensity factor. Defaults to 1.2 NOTE: this was formerly known as hue parameter

minSatscalar, optional

Sets the minimum-level saturation. Defaults to 1.2.

maxSatscalar, optional

Sets the maximum-level saturation. Defaults to 1.2.

startHuescalar, optional

Sets the starting color, ranging from [0, 360], as in D3 version by @mbostock. NOTE: overrides values in start parameter.

endHuescalar, optional

Sets the ending color, ranging from [0, 360], as in D3 version by @mbostock NOTE: overrides values in rot parameter.

minLightscalar, optional

Sets the minimum lightness value. Defaults to 0.

maxLightscalar, optional

Sets the maximum lightness value. Defaults to 1.

Returns
matplotlib.colors.LinearSegmentedColormap object
plot_helix(self, figsize=None, **kwargs)[source]

Display the RGB and luminance plots for the chosen cubehelix.

Parameters
figsizetuple of floats (N=2)

Size of the plot figure.

Returns
None
class ColormapPerception[source]

Bases: matplotlib.colors.LinearSegmentedColormap, empyre.vis.colors.Colormap3D

A perceptual colormap based on face-based luminance matching.

Based on a publication by Kindlmann et. al. http://www.cs.utah.edu/~gk/papers/vis02/FaceLumin.pdf This colormap tries to achieve an isoluminant perception by using a list of colors acquired through face recognition studies. It is a lot better than the HLS colormap, but still not completely isoluminant (despite its name). Also it appears a bit dark.

class ColormapHLS[source]

Bases: matplotlib.colors.ListedColormap, empyre.vis.colors.Colormap3D

Colormap subclass for encoding directions with colors.

This class is a subclass of the ListedColormap class. The class follows the HSL (‘hue’, ‘saturation’, ‘lightness’) ‘Double Hexcone’ Model with the saturation always set to 1 (moving on the surface of the color cylinder) with a lightness of 0.5 (full color). The three prime colors (rgb) are spaced equidistant with 120° space in between, according to a triadic arrangement. Even though the lightness is constant in the plane, the luminance (which is a weighted sum of the RGB components which encompasses human perception) is not, which can lead to artifacts like reliefs. Converting the map to a grayscale show spokes at the secondary colors. For more information see: https://vis4.net/blog/posts/avoid-equidistant-hsv-colors/ http://www.workwithcolor.com/color-luminance-2233.htm http://blog.asmartbear.com/color-wheels.html

class ColormapClassic[source]

Bases: matplotlib.colors.LinearSegmentedColormap, empyre.vis.colors.Colormap3D

Colormap subclass for encoding directions with colors.

This class is a subclass of the LinearSegmentedColormap class. The class follows the HSL (‘hue’, ‘saturation’, ‘lightness’) ‘Double Hexcone’ Model with the saturation always set to 1 (moving on the surface of the color cylinder) with a luminance of 0.5 (full color). The colors follow a tetradic arrangement with four colors (red, green, blue and yellow) arranged with 90° spacing in between.

class ColormapTransparent(r=0.0, g=0.0, b=0.0, alpha_range=None)[source]

Bases: matplotlib.colors.LinearSegmentedColormap

Colormap subclass for including transparency.

This class is a subclass of the LinearSegmentedColormap class with integrated support for transparency. The colormap is unicolor and varies only in transparency.

Attributes
r: float, optional

Intensity of red in the colormap. Has to be between 0. and 1.

g: float, optional

Intensity of green in the colormap. Has to be between 0. and 1.

b: float, optional

Intensity of blue in the colormap. Has to be between 0. and 1.

alpha_rangelist (N=2) of float, optional

Start and end alpha value. Has to be between 0. and 1.

interpolate_color(fraction, start, end)[source]

Interpolate linearly between two color tuples (e.g. RGB).

Parameters
fraction: float or :class:`~numpy.ndarray`

Interpolation fraction between 0 and 1, which determines the position of the interpolation between start and end.

start: tuple (N=3) or :class:`~numpy.ndarray`

Start of the interpolation as a tuple of three numbers or a numpy array, where the last dimension should have length 3 and contain the color tuples.

end: tuple (N=3) or :class:`~numpy.ndarray`

End of the interpolation as a tuple of three numbers or a numpy array, where the last dimension should have length 3 and contain the color tuples.

Returns
result: tuple (N=3) or ndarray

Result of the interpolation as a tuple of three numbers or a numpy array, where the last dimension should has length 3 and contains the color tuples.

The tools module

This module provides helper functions to the vis module.

new(nrows=1, ncols=1, mode='image', figsize=None, textwidth=None, width_scale=1.0, aspect=None, **kwargs)[source]

Convenience function for the creation of a new subplot grid (wraps ~matplotlib.pyplot.subplots).

If you use the textwidth parameter, plot sizes are fitting into publications with LaTeX. Requires two stylesheets empyre-image and empyre-plot corresponding to its two mode settings. Those stylesheets use constrained_layout=True to achieve well behaving plots without much whitespace around. This function should work fine for a small number of images (e.g. 1, 2x2, etc.), for more fine grained control, the contexts can be used directly if they are installed corretly, or use width_scale to build the images separately (e.g. 2 adjacent with width=0.5). For images, it is assumed that most images are square (and therefore aspect=1).

Parameters
nrowsint, optional

Number of rows of the subplot grid, by default 1

ncolsint, optional

Number of columns of the subplot grid, by default 1

mode{‘image’, ‘plot’}, optional

Mode of the new subplot grid, by default ‘image’. Both modes have dedicated matplotlib styles which are used and which are installed together with EMPyRe. The ‘image’ mode disables axis labels and ticks, mainly intended to be used with ~matplotlib.pyplot.imshow with ~empyre.vis.decorators.scalebar, while the ‘plot’ mode should be used for traditional plots like with ~matplotlib.pyplot.plot or ~matplotlib.pyplot.scatter.

figsize(float, float), optional

Width and height of the figure in inches, defaults to rcParams[“figure.figsize”], which depends on the chosen stylesheet. If set, this will overwrite all other following parameters.

textwidthfloat, optional

The textwidth of your LaTeX document in points, which you can get by using \(\the\textwidth\). If this is not None (the default), this will be used to define the figure size if it is not set explicitely.

width_scalefloat, optional

Only meaningful if textwidth is set. If it is, width_scale will be a scaling factor for the figure width. Example: if you set this to 0.5, your figure will span half of the textwidth. Default is 1.

aspectfloat, optional

Aspect ratio of the figure height relative to the figure width. If None (default), the aspect is set to be 1 for mode=image and to ‘golden’ for mode=plot, which adjusts the aspect to represent the golden ratio of 0.6180… If ncols!=nrows, it often makes sense to use aspect=nrows/ncols here.

Returns
figFigure

The constructed figure.

axesaxes.Axes object or array of Axes objects.

axes can be either a single Axes object or an array of Axes objects if more than one subplot was created. The dimensions of the resulting array can be controlled with the squeeze keyword argument.

Notes

additional kwargs are passed to ~matplotlib.pyplot.subplots.

savefig(fname, **kwargs)[source]

Utility wrapper around savefig() to save the current figure.

Parameters
fnamestr or PathLike or file-like object

Path to the file wherein the figure should be saved.

Notes

Uses the ‘empyre-save’ stylesheet (installed together with EMPyRe to control the saving behaviour. Any kwargs are passed to savefig().

calc_figsize(textwidth=None, width_scale=1.0, aspect=1)[source]

Helper function to calculate the figure size from various parameters. Useful for publications via LaTeX.

Parameters
textwidthfloat, optional

The textwidth of your LaTeX document in points, which you can get by using \(\the\textwidth\). If this is None (default), the standard width in inches from the current stylesheet is used.

width_scalefloat, optional

Scaling factor for the figure width. Example: if you set this to 0.5, your figure will span half of the textwidth. Default is 1.

aspectfloat, optional

Aspect ratio of the figure height relative to the figure width. If None (default), the aspect is set to be 1 for mode=image and to ‘golden’ for mode=plot, which adjusts the aspect to represent the golden ratio of 0.6180…

Returns
figsize: (float, float)

The determined figure size

Notes

Based on snippet by Florian Winkler.

use_style(stylename)[source]

Context that uses a matplotlib stylesheet. Can fall back to local mpl stylesheets if necessary!

Parameters
stylenamestr

A style specification.

Yields
context

Context manager for using style settings temporarily.

copy_mpl_stylesheets()[source]

Copy matplotlib styles to the users matplotlib config directory. Useful if you want to utilize them elsewhere.

Notes

You might need to restart your Python session for the stylesheets to be recognized/found!