Custom plot functions¶
Overview¶
Set axes limits¶
Return [np.min(a), np.max(a)] |
|
|
Scale limits to be 5% wider, to have a nice plot. |
|
Set limits the the floor/ceil values in terms of decades. |
Ticks¶
|
Get and/or apply ticks and tick-labels between two bounds. Example: select a fraction of the default ticks along an axis::. |
|
See |
|
See |
|
Get and/or apply major ticks and tick-labels between two bounds. Example: select a fraction of the default major ticks along an axis::. |
|
See |
|
See |
|
Get and/or apply minor ticks and tick-labels between two bounds. Example: select a fraction of the default minor ticks along an axis::. |
|
See |
|
See |
Plot in relative coordinates¶
|
Plot. |
|
Plot a text. |
|
Transform relative x-coordinates to absolute x-coordinates. |
|
Transform relative y-coordinates to absolute y-coordinates. |
|
Transform absolute x-coordinates to relative x-coordinates. |
|
Transform absolute y-coordinates to relative y-coordinates. |
Fit¶
|
Fit a powerlaw \(y = c x^b\) by a linear fitting of \(\ln y = \ln c + b \ln x\). |
|
Fit an exponential \(y = c \exp(b x)\) by linear fitting of :math`ln y = ln c + b x`. |
|
Fit a linear function \(y = a + b x\). |
Annotate power-law¶
|
Draw a power-law grid: a grid that respects a certain power-law exponent. |
|
Plot a power-law. |
|
Added a label to the middle of a power-law annotation (see |
|
Set the limits such that a power-law with a certain exponent lies on the diagonal. |
Plot mesh¶
|
Add patches to plot. |
(Plot) statistics¶
|
Compute histogram. |
|
Determine bin-edges. |
Merge bins with right-neighbour until each bin has a minimum width. |
|
|
Merge bins with right-neighbour until each bin has a minimum number of data-points. |
|
Merge bins not encompassing an integer with the preceding bin. |
|
Return the midpoints of every bin-edge. |
|
(Re)normalise a histogram. |
|
Compute cumulative histogram. |
|
Cumulative distribution function: |
|
Complementary cumulative distribution function: |
|
Plot histogram. |
|
Generate a random number based on a discrete cumulative probability density function. |
LaTeX¶
|
Convert a number to a LaTeX notation. |
Return |
|
Find an available font to mimic LaTeX, and return its name. |
Styles¶
|
Run |
|
Run |
|
Run |
Write all goose-styles to the relevant matplotlib configuration directory. |
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.
- x (
- Options:
- axis ([
plt.gca()] | …) Specify the axis to which to apply the limits.
- axis ([
- Returns:
- x (
float,list) Relative coordinates.
- x (
- 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.
- y (
- Options:
- axis ([
plt.gca()] | …) Specify the axis to which to apply the limits.
- axis ([
- Returns:
- y (
float,list) Relative coordinates.
- y (
- 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.
- exp (
- Options:
- width, height, endx, endy (
float) Definition of the end coordinate (only on of these options is needed).
- rx, ry ([
0.5] |float) x- and y-position of the label relative to the width and the height of the power-law annotation line (as can be plotted by
goosempl.plot_powerlaw). E.g.rx = 0.5, ry = 0.5corresponds to the middle of the line.- 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.
- width, height, endx, endy (
- Returns:
The handle of the
plt.text(...)command.
- GooseMPL.asLinearSegmentedColormap(cmap: ArrayLike, name: str = 'mycolormap') LinearSegmentedColormap¶
Convert matrix of colors to a linear segmented colormap. See this answer for more details.
- Parameters:
cmap – Matrix of colors [n, 3].
- Returns:
The LinearSegmentedColormap.
- GooseMPL.bin(x: ArrayLike, y: ArrayLike, bin_edges: ArrayLike | int, use_median: bool = False, return_n: bool = False)¶
Bin data.
- Parameters:
x – x-data.
y – y-data.
bin_edges – Bin-edges along the x-axis, or the number of bins.
use_median – Use median instead of mean.
return_n – Return the number of points in each bin (as dictionary entry “n”).
- Returns:
Dictionary as follows:: x: mean(x) for each bin (or median(x) if use_median = True). y: mean(y) for each bin (or median(y) if use_median = True). xerr: std(x) for each bin. yerr: std(y) for each bin.
- GooseMPL.ccdf(data: ArrayLike, greater_equal: bool = True)¶
Complementary cumulative distribution function:
P(x >= X). By definition:ccdf(data)[0] == 1 - cdf(data)[0]).- Parameters:
data – Input data.
greater_equal – If
TruereturnP(x >= X), ifFalse return ``P(x > X).
- Returns:
(P, X)
- GooseMPL.cdf(data: ArrayLike, less_equal: bool = False)¶
Cumulative distribution function:
P(x < X).- Parameters:
data – Input data.
less_equal – If
TruereturnP(x <= X), ifFalse return ``P(x < X).
- Returns:
(P, X)
- GooseMPL.close(*args, **kwargs)¶
Run
matplotlib.pyplot.close.
- 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.
- exp (
- Options:
- axis ([
plt.gca()] | …) Specify the axis to which to apply the limits.
- plot ([
False] |True) Plot the diagonal.
- …
Any
plt.plot(...)option.
- axis ([
- 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.fit_exp(xdata: ArrayLike, ydata: ArrayLike, yerr: ArrayLike = None, yerr_mode: str = 'differentials', absolute_sigma: bool = True, prefactor: float = None, exponent: float = None, axis: Axes = None, fmt: str = None, auto_fmt: str = None, extrapolate: bool | dict = False, **kwargs) dict¶
Fit an exponential \(y = c \exp(b x)\) by linear fitting of :math`ln y = ln c + b x`. This function does not support more customised operation like fitting an offset, but custom code can be easily written by copy/pasting from here.
Warning
If this function is used to plot the fit, beware that the fit is plotted using just two data-points if the axis is set to semilogy-scale (as the fit will be a straight line on that scale).
Different modes are available to treat
yerr:"differentials": assume thatyerr << ydata, such that\[\begin{split}z &\equiv \ln y \\ \delta z &= \left| \frac{\partial z}{\partial y} \right| \delta y \\ \delta z &= \frac{\delta y}{y}\end{split}\]
See also
- Parameters:
xdata – Data points along the x-axis.
ydata – Data points along the y-axis.
yerr – Error-bar for
ydata.yerr_mode – How to treat the error in
ydata, see above.absolute_sigma – Treat (the effective)
yerras absolute error.prefactor – Prefactor \(c\) (fitted if not specified).
exponent – Exponent \(b\) (fitted if not specified).
axis – Axis to plot along (not plotted if not specified).
fmt – Format for the label (if plotting). E.g.
r"${0:.3f} \exp ({1:.2f} x)$".auto_fmt – Format label (if plotting) as
r"${0:.3f} \exp ({1:.2f} x)$", withxreplaced with the specified string.extrapolate – Plot the function on the full range of
axis.get_xlim(). Instead ofTrue'', one can specify plot options for the extrapolated line, e.g. ``..., extrapolate=dict(ls="--", c="r"), ....kwargs – Other plot options.
- Returns:
The fit (and plot) details as a dictionary:
prefactor: (Fitted) prefactor. exponent: (Fitted) exponent. prefactor_error: Estimated error of prefactor. exponent_error: Estimated error of exponent. pcov: Covariance of fit. label: Label. handle: Handle of the plot (if ``axis`` was specified). handle_lower: Handle of the plot of the lower extrapolation, if present. handle_upper: Handle of the plot of the upper extrapolation, if present.
- GooseMPL.fit_linear(xdata: ArrayLike, ydata: ArrayLike, yerr: ArrayLike = None, absolute_sigma: bool = True, offset: float = None, slope: float = None, axis: Axes = None, fmt: str = None, auto_fmt: str = None, extrapolate: bool | dict = False, **kwargs) dict¶
Fit a linear function \(y = a + b x\).
See also
- Parameters:
xdata – Data points along the x-axis.
ydata – Data points along the y-axis.
yerr – Error-bar for
ydata.absolute_sigma – Treat (the effective)
yerras absolute error.offset – Offset \(a\) (fitted if not specified).
slope – Slope \(b\) (fitted if not specified).
axis – Axis to plot along (not plotted if not specified).
fmt – Format for the label, e.g.
r"${offset:.2f} + {slope:.2f} x$".auto_fmt – Format label as
r"$({offset:.2f} \pm {offset_error:.2f}) + ({slope:.2f} \pm {slope_error:.2f}) x$", withxreplaced with the specified string.extrapolate – Plot the function on the full range of
axis.get_xlim(). Instead ofTrue, one can specify plot options for the extrapolated line, e.g...., extrapolate=dict(ls="--", c="r"), ....kwargs – Other plot options.
- Returns:
The fit (and plot) details as a dictionary:
offset: (Fitted) offset. slope: (Fitted) slope. offset_error: Estimated error of offset. slope_error: Estimated error of slope. pcov: Covariance of fit. label: Label. handle: Handle of the plot (if ``axis`` was specified). handle_lower: Handle of the plot of the lower extrapolation, if present. handle_upper: Handle of the plot of the upper extrapolation, if present.
- GooseMPL.fit_log(xdata: ArrayLike, ydata: ArrayLike, yerr: ArrayLike = None, **kwargs) dict¶
Fit a logarithm \(y = a + b \ln x\). See documentation of
fit_linear().
- GooseMPL.fit_powerlaw(xdata: ArrayLike, ydata: ArrayLike, yerr: ArrayLike = None, yerr_mode: str = 'differentials', absolute_sigma: bool = True, prefactor: float = None, exponent: float = None, axis: Axes = None, fmt: str = None, auto_fmt: str = None, extrapolate: bool | dict = False, **kwargs) dict¶
Fit a powerlaw \(y = c x^b\) by a linear fitting of \(\ln y = \ln c + b \ln x\).
Note
This function does not support more customised operation like fitting an offset, but custom code can be easily written by copy/pasting from here.
Warning
If this function is used to plot the fit, beware that the fit is plotted using just two data-points if the axis is set to log-log scale (as the fit will be a straight line on that scale).
Different modes are available to treat an error estimate (
yerr) inydata:"differentials": assume thatyerr << ydata, such that\[\begin{split}z &\equiv \ln y \\ \delta z &= \left| \frac{\partial z}{\partial y} \right| \delta y \\ \delta z &= \frac{\delta y}{y}\end{split}\]
See also
- Parameters:
xdata – Data points along the x-axis.
ydata – Data points along the y-axis.
yerr – Error-bar for
ydata(should be the standard deviation).yerr_mode – How to treat the error in
ydata, see above.absolute_sigma – Treat (the effective)
yerras absolute error.prefactor – Prefactor \(c\) (fitted if not specified).
exponent – Exponent \(b\) (fitted if not specified).
axis – Axis to plot along (not plotted if not specified).
fmt – Format for the label, e.g.
r"${prefactor:.2f} x^{{{exponent:.2f}}}$".auto_fmt – Format label as
r"$({prefactor:.2f} \pm {prefactor_error:.2f}) x^{{{exponent:.2f} \pm {exponent_error:.2f}}}$", withxreplaced with the specified string.extrapolate – Plot the function on the full range of
axis.get_xlim(). Instead ofTrue, one can specify plot options for the extrapolated line, e.g...., extrapolate=dict(ls="--", c="r"), ....kwargs – Other plot options.
- Returns:
The fit (and plot) details as a dictionary:
prefactor: (Fitted) prefactor. exponent: (Fitted) exponent. prefactor_error: Estimated error of prefactor. exponent_error: Estimated error of exponent. pcov: Covariance of fit. label: Label. handle: Handle of the plot (if ``axis`` was specified). handle_lower: Handle of the plot of the lower extrapolation, if present. handle_upper: Handle of the plot of the upper extrapolation, if present.
- 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.
- exp (
- 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.
- insert (
- Returns:
The handle of the
plt.plot(...)command.
- GooseMPL.hist(P, edges, **kwargs)¶
Plot histogram.
- GooseMPL.histogram(data, return_edges=True, **kwargs)¶
Compute histogram. This function passes all options to numpy.histrogram In addition you can use:
- Parameters:
return_edges – 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.
- data (
- 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. *'voronoi': each bin is the region between two adjacent data-points.- 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.
- bins ([
- Returns:
- bin_edges (
<array of dtype float>) The edges to pass into histogram.
- bin_edges (
- GooseMPL.histogram_bin_edges2midpoint(bin_edges: ArrayLike)¶
Return the midpoints of every bin-edge.
- Parameters:
bin_edges – Bin-edges.
count – Count per bin.
norm – Area of the histogram.
- GooseMPL.histogram_bin_edges_integer(bin_edges)¶
Merge bins not encompassing an integer with the preceding bin. For example: a bin with edges
[1.1, 1.9]is removed, but[0.9, 1.1]is not removed.- Parameters:
bin_edges (array_like) – Bin-edges.
- Returns:
Bin-edges.
- 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.
- data (
- 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.
- bins (
- 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.
- return_edges ([
- GooseMPL.histogram_norm(count: ArrayLike, bin_edges: ArrayLike, norm: float = 1.0)¶
(Re)normalise a histogram.
- Parameters:
count – Count.
bin_edges – Bin-edges.
norm – Area of the histogram.
- GooseMPL.histogram_rebin(count: ArrayLike, bin_edges: ArrayLike, group: int = 100, strip: bool = False)¶
Rebin a histogram.
- Parameters:
count – Count per bin.
bin_edges – Bin-edges.
group – Number of bins to group.
strip – Strip empty bins at the beginning and end.
- Returns:
count, bin_edges
- GooseMPL.latex_float(number, fmt='{0:.2g}')¶
Convert a number to a LaTeX notation. See this answer
- Argument:
- number (
<float>) A number.
- number (
- Options:
- fmt (
<str>| ['{0:.2g}']) Format used to to initially convert the number to a string.
- fmt (
- Returns:
- string (
<str>) The number in LaTeX notation.
- string (
- GooseMPL.log_format(base, ticks)¶
Format a list of ticks to LaTeX notation.
- Parameters:
base – The base of the exponents.
ticks – The ticks.
- Returns:
The formatted ticks.
- GooseMPL.log_format_text_minus(base, ticks)¶
Format a list of ticks to LaTeX notation. If the exponent is negative, the minus sign is formatted as a LaTeX text (shorter minus sign).
- Parameters:
base – The base of the exponents.
ticks – The ticks.
- Returns:
The formatted ticks.
- GooseMPL.log_minorticks(lim: tuple(float, float) = None, keep: list = None, axis: plt.Axes = None, direction: str = 'x')¶
Get and/or apply minor ticks and tick-labels between two bounds. Example: select a fraction of the default minor ticks along an axis:
log_minorticks(keep=[0, -1], axis=ax)
Example: get ticks and labels (without applying them to a plot):
>>> ticks, labels = log_ticks((0, 1)) >>> print(ticks) [2, 3, 4, 5, 6, 7, 8, 9] >>> print(labels) ["2", "3", "4", "5", "6", "7", "8", "9"]
- Parameters:
lim – Lower- and upper-bound. Default: read from
axisorplt.gca(),keep – Keep only a selection of labels, convert the rest to empty strings.
axis – Apply ticks/labels to an axis. Ticks are only applied if the axis is specified.
direction – “x” or “y”.
- Returns:
ticks, labels
- GooseMPL.log_minorxticks(*args, **kwargs)¶
See
log_minorticks().
- GooseMPL.log_minoryticks(*args, **kwargs)¶
See
log_minorticks().
- GooseMPL.log_ticks(lim: tuple(int, int) = None, keep: list = None, base: int | float = 10, axis: plt.Axes = None, direction: str = 'x', minor: bool = True, formatter: callable = <function log_format>) -> (list, list)¶
Get and/or apply major ticks and tick-labels between two bounds. Example: select a fraction of the default major ticks along an axis:
log_ticks(keep=[0, -1], axis=ax) log_ticks(keep=slice(0, None, 2), axis=ax)
Example: get ticks and labels (without applying them to a plot):
>>> ticks, labels = log_ticks((0, 3)) >>> print(ticks) [1, 10, 100, 1000] >>> print(labels) ['$10^{0}$', '$10^{1}$', '$10^{2}$', '$10^{3}$']
- Parameters:
lim – Lower- and upper-bound exponent. Default: read from
axisorplt.gca().keep – Keep only a selection of labels, convert the rest to empty strings.
base – The base of the exponents.
axis – Apply ticks/labels to an axis. Ticks are only applied if the axis is specified.
direction – “x” or “y”.
minor – Use minor ticks: minor ticks are placed without labels, they are not returned.
formatter – Function to format the ticks. Called
formatter(base, ticks).
- Returns:
ticks, labels
- GooseMPL.log_xticks(*args, **kwargs)¶
See
log_ticks().
- GooseMPL.log_yticks(*args, **kwargs)¶
See
log_ticks().
- GooseMPL.minmax(a)¶
Return [np.min(a), np.max(a)]
- 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
coorandconn.
- patches (
- 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).
- coor (
- 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).
- cindex (
- 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.
- cmap (
- Returns:
- handle (
<matplotlib>) Handle of the patch objects.
- handle (
See also
- GooseMPL.plot(x, y, units='absolute', axis=None, **kwargs)¶
Plot.
- Arguments:
- x, y (
list) Coordinates.
- x, y (
- 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.
- units ([
- 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.
- exp (
- 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.
- return_parameters ([
False] |True) If
Truethe output is a tuple: the handle of the plot, and the parameters that define the powerlaw: the constant and the exponent.
- …
Any
plt.plot(...)option.
- width, height, endx, endy (
- Returns:
The handle of the
plt.plot(...)command.
- GooseMPL.random_from_cdf(shape, P, x, linspace=False, shuffle=True)¶
Generate a random number based on a discrete cumulative probability density function.
- Arguments:
- shape (
`<array_like>) Shape of the output array.
- P, x (
`<array_like>) Cumulative probability of each data point
x.
- shape (
- Options:
- linspace ([
False] |True) If
Truethe cumulative probabilities of the output array are drawn from an equally spaced array. Otherwise they are drawn randomly.- shuffle ([
True] |False) If
Truethe output is shuffled (before reshaping), otherwise the output it sorted.
- linspace ([
- 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.
- x (
- Options:
- axis ([
plt.gca()] | …) Specify the axis to which to apply the limits.
- axis ([
- Returns:
- x (
float,list) Absolute coordinates.
- x (
- 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.
- y (
- Options:
- axis ([
plt.gca()] | …) Specify the axis to which to apply the limits.
- axis ([
- Returns:
- y (
float,list) Absolute coordinates.
- y (
- GooseMPL.restore_data(data, key, axis=None)¶
Restore plot from HDF5-file.
- Arguments:
- data (
h5py.File) Opened HDF5 file.
- key (
<str>) Name of the dataset from which to read.
- data (
- Options:
- axis ([
plt.gca()] | …) Specify the axis on which to plot.
- axis ([
- Returns:
- handle
The handle of the created plot.
Deprecated since version 0.6.0: Use openscienceplot_matplotlib
- GooseMPL.savefig(*args, **kwargs)¶
Run
matplotlib.pyplot.savefigwhile making sure that the directory exists.
- 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.
- lim (
- Options:
- factor ([
1.05] |<float>) Scale factor.
- 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).
- axis ([
- GooseMPL.subplots(scale_x=None, scale_y=None, scale=None, **kwargs)¶
Run
matplotlib.pyplot.subplotswithfigsizeset to the correct multiple of the default.- Additional options:
- scale, scale_x, scale_y (
<float>) Scale the figure-size (along one of the dimensions).
- scale, scale_x, scale_y (
- GooseMPL.system_has_latex()¶
Return
Trueif the system has LaTeX installed.
- GooseMPL.text(x, y, text, units='absolute', axis=None, **kwargs)¶
Plot a text.
- Arguments:
- x, y (
float) Coordinates.
- text (
str) Text to plot.
- x, y (
- 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.
- units ([
- Returns:
The handle of the
plt.text(...)command.
- GooseMPL.ticks(keep: list = None, axis: plt.Axes = None, direction: str = 'x', autofmt: bool = True)¶
Get and/or apply ticks and tick-labels between two bounds. Example: select a fraction of the default ticks along an axis:
ticks(keep=[0, -1], axis=ax) ticks(keep=slice(0, None, 2), axis=ax)
- Parameters:
keep – Keep only a selection of labels, convert the rest to empty strings.
axis – Apply ticks/labels to an axis. Ticks are only applied if the axis is specified.
direction – “x” or “y”.
autofmt – Re-apply automatic formatting to the remaining ticks.
- Returns:
ticks, labels
- GooseMPL.write_data(data, key, handle)¶
Save plot data to HDF5-file.
- Arguments:
- data (
h5py.File) Opened HDF5 file.
- key (
<str>) Name of the dataset to which to write.
- handle
The handle to write.
- data (
Deprecated since version 0.6.0: Use openscienceplot_matplotlib