GooseMPL custom plot functions

Overview

Set axes limits

GooseMPL.scale_lim(lim[, factor]) Scale limits to be 5% wider, to have a nice plot.
GooseMPL.set_decade_lims([axis, direction]) Set limits the the floor/ceil values in terms of decades.

Plot in relative coordinates

GooseMPL.plot(x, y[, units, axis]) Plot.
GooseMPL.text(x, y, text[, units, axis]) Plot a text.
GooseMPL.rel2abs_x(x[, axis]) Transform relative x-coordinates to absolute x-coordinates.
GooseMPL.rel2abs_y(y[, axis]) Transform relative y-coordinates to absolute y-coordinates.
GooseMPL.abs2rel_x(x[, axis]) Transform absolute x-coordinates to relative x-coordinates.
GooseMPL.abs2rel_y(y[, axis]) Transform absolute y-coordinates to relative y-coordinates.

Annotate power-law

GooseMPL.grid_powerlaw(exp[, insert, skip, …]) Draw a power-law grid: a grid that respects a certain power-law exponent.
GooseMPL.plot_powerlaw(exp, startx, starty) Plot a power-law.
GooseMPL.annotate_powerlaw(text, exp, …[, …]) Added a label to the middle of a power-law annotation (see goosempl.plot_powerlaw).
GooseMPL.diagonal_powerlaw(exp[, ll, lr, …]) Set the limits such that a power-law with a certain exponent lies on the diagonal.

Plot mesh

GooseMPL.patch(*args, **kwargs) Add patches to plot.

(Plot) statistics

GooseMPL.histogram(data[, return_edges]) Compute histogram.
GooseMPL.histogram_bin_edges(data[, bins, …]) Determine bin-edges.
GooseMPL.histogram_bin_edges_minwidth(…) Merge bins with right-neighbour until each bin has a minimum width.
GooseMPL.histogram_bin_edges_mincount(data, …) Merge bins with right-neighbour until each bin has a minimum number of data-points.
GooseMPL.histogram_cumulative(data, **kwargs) Compute cumulative histogram.
GooseMPL.cdf(data[, mode]) Return cumulative density.
GooseMPL.hist(P, edges, **kwargs) Plot histogram.

Styles

GooseMPL.subplots(**kwargs) Run matplotlib.pyplot.subplots with figsize set to the correct multiple of the default.
GooseMPL.copy_style() Write all goose-styles to the relevant matplotlib configuration directory.
GooseMPL.find_latex_font_serif() Find an available font to mimic LaTeX, and return its name.

Documentation

This module provides some extensions to matplotlib.

dependencies:
  • numpy
  • matplotlib
copyright:
GooseMPL.abs2rel_x(x, axis=None)

Transform absolute x-coordinates to relative x-coordinates. Relative coordinates correspond to a fraction of the relevant axis. Be sure to set the limits and scale before calling this function!

Arguments:
x (float, list)

Absolute coordinates.

Options:
axis ([plt.gca()] | …)

Specify the axis to which to apply the limits.

Returns:

x (float, list)

Relative coordinates.

GooseMPL.abs2rel_y(y, axis=None)

Transform absolute y-coordinates to relative y-coordinates. Relative coordinates correspond to a fraction of the relevant axis. Be sure to set the limits and scale before calling this function!

Arguments:
y (float, list)

Absolute coordinates.

Options:
axis ([plt.gca()] | …)

Specify the axis to which to apply the limits.

Returns:

y (float, list)

Relative coordinates.

GooseMPL.annotate_powerlaw(text, exp, startx, starty, width=None, rx=0.5, ry=0.5, **kwargs)

Added a label to the middle of a power-law annotation (see goosempl.plot_powerlaw).

Arguments:
exp (float)

The power-law exponent.

startx, starty (float)

Start coordinates.

Options:
width, height, endx, endy (float)

Definition of the end coordinate (only on of these options is needed).

rx, ry (float)

Shift in x- and y-direction w.r.t. the default coordinates.

units (['relative'] | 'absolute')

The type of units in which the coordinates are specified. Relative coordinates correspond to a fraction of the relevant axis. If you use relative coordinates, be sure to set the limits and scale before calling this function!

axis ([plt.gca()] | …)

Specify the axis to which to apply the limits.

Any plt.text(...) option.

Returns:

The handle of the plt.text(...) command.

GooseMPL.cdf(data, mode='continuous', **kwargs)

Return cumulative density.

Arguments:
data (<numpy.ndarray>)

Input data, to plot the distribution for.

Returns:

P (<numpy.ndarray>)

Cumulative probability.

x (<numpy.ndarray>)

Data points.

GooseMPL.copy_style()

Write all goose-styles to the relevant matplotlib configuration directory.

GooseMPL.diagonal_powerlaw(exp, ll=None, lr=None, tl=None, tr=None, width=None, height=None, plot=False, **kwargs)

Set the limits such that a power-law with a certain exponent lies on the diagonal.

Arguments:
exp (<float>)

The power-law exponent.

ll, lr, tl, tr (<list>)

Coordinates of the lower-left, or the lower-right, or the top-left, or the top-right corner.

width, height (<float>)

Width or the height.

Options:
axis ([plt.gca()] | …)

Specify the axis to which to apply the limits.

plot ([False] | True)

Plot the diagonal.

Any plt.plot(...) option.

Returns:

The handle of the plt.plot(...) command (if any).

GooseMPL.find_latex_font_serif()

Find an available font to mimic LaTeX, and return its name.

GooseMPL.grid_powerlaw(exp, insert=0, skip=0, end=-1, step=0, axis=None, **kwargs)

Draw a power-law grid: a grid that respects a certain power-law exponent. The grid-lines start from the positions of the ticks.

Arguments:
exp (float)

The power-law exponent.

Options:
insert (<int>)

Insert extra lines in between the default lines set by the tick positions.

skip, end, step (<int>)

Select from the lines based on coor = coor[skip:end:step].

axis ([plt.gca()] | …)

Specify the axis to which to apply the limits.

Any plt.plot(...) option.

Returns:

The handle of the plt.plot(...) command.

GooseMPL.hist(P, edges, **kwargs)

Plot histogram.

GooseMPL.histogram(data, return_edges=True, **kwargs)

Compute histogram. See numpy.histrogram

Extra options:
return_edges ([True] | [False])

Return the bin edges if set to True, return their midpoints otherwise.

GooseMPL.histogram_bin_edges(data, bins=10, mode='equal', min_count=None, integer=False, remove_empty_edges=True, min_width=None)

Determine bin-edges.

Arguments:
data (<array_like>)

Input data. The histogram is computed over the flattened array.

Options:
bins ([10] | <int>)

The number of bins.

mode (['equal' | <str>)

Mode with which to compute the bin-edges: * 'equal': each bin has equal width. * 'log': logarithmic spacing. * 'uniform': uniform number of data-points per bin.

min_count (<int>)

The minimum number of data-points per bin.

min_width (<float>)

The minimum width of each bin.

integer ([False] | [True])

If True, bins not encompassing an integer are removed (e.g. a bin with edges [1.1, 1.9] is removed, but [0.9, 1.1] is not removed).

remove_empty_edges ([True] | [False])

Remove empty bins at the beginning or the end.

Returns:

bin_edges (<array of dtype float>)

The edges to pass into histogram.

GooseMPL.histogram_bin_edges_mincount(data, min_count, bins)

Merge bins with right-neighbour until each bin has a minimum number of data-points.

Arguments:
data (<array_like>)

Input data. The histogram is computed over the flattened array.

bins (<array_like> | <int>)

The bin-edges (or the number of bins, automatically converted to equal-sized bins).

min_count (<int>)

The minimum number of data-points per bin.

GooseMPL.histogram_bin_edges_minwidth(min_width, bins)

Merge bins with right-neighbour until each bin has a minimum width.

Arguments:
bins (<array_like>)

The bin-edges.

min_width (<float>)

The minimum bin width.

GooseMPL.histogram_cumulative(data, **kwargs)

Compute cumulative histogram. See numpy.histrogram

Extra options:
return_edges ([True] | [False])

Return the bin edges if set to True, return their midpoints otherwise.

normalize ([False] | True)

Normalize such that the final probability is one. In this case the function returns the (binned) cumulative probability density.

GooseMPL.patch(*args, **kwargs)

Add patches to plot. The color of the patches is indexed according to a specified color-index.

Example:

Plot a finite element mesh: the outline of the undeformed configuration, and the deformed configuration for which the elements get a color e.g. based on stress:

import matplotlib.pyplot as plt
import goosempl          as gplt

fig,ax = plt.subplots()

p = gplt.patch(coor=coor+disp,conn=conn,axis=ax,cindex=stress,cmap='YlOrRd',edgecolor=None)
_ = gplt.patch(coor=coor     ,conn=conn,axis=ax)

cbar = fig.colorbar(p,axis=ax,aspect=10)

plt.show()
Arguments - option 1/2:
 
patches (<list>)

List with patch objects. Can be replaced by specifying coor and conn.

Arguments - option 2/2:
 
coor (<numpy.ndarray> | <list> (nested))

Matrix with on each row the coordinates (positions) of each node.

conn (<numpy.ndarray> | <list> (nested))

Matrix with on each row the number numbers (rows in coor) which form an element (patch).

Options:
cindex (<numpy.ndarray>)

Array with, for each patch, the value that should be indexed to a color.

axis (<matplotlib>)

Specify an axis to include to plot in. By default the current axis is used.

autoscale ([True] | False)

Automatically update the limits of the plot (currently automatic limits of Collections are not supported by matplotlib).

Recommended options:
 
cmap (<str> | …)

Specify a colormap.

linewidth (<float>)

Width of the edges.

edgecolor (<str> | …)

Color of the edges.

clim ((<float>,<float>))

Lower and upper limit of the color-axis.

Returns:

handle (<matplotlib>)

Handle of the patch objects.

See also

GooseMPL.plot(x, y, units='absolute', axis=None, **kwargs)

Plot.

Arguments:
x, y (list)

Coordinates.

Options:
units (['absolute'] | 'relative')

The type of units in which the coordinates are specified. Relative coordinates correspond to a fraction of the relevant axis. If you use relative coordinates, be sure to set the limits and scale before calling this function!

Any plt.plot(...) option.

Returns:

The handle of the plt.plot(...) command.

GooseMPL.plot_powerlaw(exp, startx, starty, width=None, **kwargs)

Plot a power-law.

Arguments:
exp (float)

The power-law exponent.

startx, starty (float)

Start coordinates.

Options:
width, height, endx, endy (float)

Definition of the end coordinate (only on of these options is needed).

units (['relative'] | 'absolute')

The type of units in which the coordinates are specified. Relative coordinates correspond to a fraction of the relevant axis. If you use relative coordinates, be sure to set the limits and scale before calling this function!

axis ([plt.gca()] | …)

Specify the axis to which to apply the limits.

Any plt.plot(...) option.

Returns:

The handle of the plt.plot(...) command.

GooseMPL.rel2abs_x(x, axis=None)

Transform relative x-coordinates to absolute x-coordinates. Relative coordinates correspond to a fraction of the relevant axis. Be sure to set the limits and scale before calling this function!

Arguments:
x (float, list)

Relative coordinates.

Options:
axis ([plt.gca()] | …)

Specify the axis to which to apply the limits.

Returns:

x (float, list)

Absolute coordinates.

GooseMPL.rel2abs_y(y, axis=None)

Transform relative y-coordinates to absolute y-coordinates. Relative coordinates correspond to a fraction of the relevant axis. Be sure to set the limits and scale before calling this function!

Arguments:
y (float, list)

Relative coordinates.

Options:
axis ([plt.gca()] | …)

Specify the axis to which to apply the limits.

Returns:

y (float, list)

Absolute coordinates.

GooseMPL.scale_lim(lim, factor=1.05)

Scale limits to be 5% wider, to have a nice plot.

Arguments:
lim (<list> | <str>)

The limits. May be a string “[…,…]”, which is converted to a list.

Options:
factor ([1.05] | <float>)

Scale factor.

GooseMPL.set_decade_lims(axis=None, direction=None)

Set limits the the floor/ceil values in terms of decades.

Options:
axis ([plt.gca()] | …)

Specify the axis to which to apply the limits.

direction ([None] | 'x' | 'y')

Limit the application to a certain direction (default: both).

GooseMPL.subplots(**kwargs)

Run matplotlib.pyplot.subplots with figsize set to the correct multiple of the default.

GooseMPL.text(x, y, text, units='absolute', axis=None, **kwargs)

Plot a text.

Arguments:
x, y (float)

Coordinates.

text (str)

Text to plot.

Options:
units (['absolute'] | 'relative')

The type of units in which the coordinates are specified. Relative coordinates correspond to a fraction of the relevant axis. If you use relative coordinates, be sure to set the limits and scale before calling this function!

Any plt.text(...) option.

Returns:

The handle of the plt.text(...) command.