API Reference¶
- dewloosh.mpl.triplot.triplot(triobj, *args, hinton=False, data=None, title=None, label=None, fig=None, ax=None, axes=None, fig_kw: Optional[dict] = None, **kwargs)[source]¶
Creates plots over triangulations using matplotlib.
- Parameters
triobj (TriMeshLike) – This is either a tuple of mesh data (coordinates and topology) or a triangulation object understood by dewloosh.tri.trimesh.triangulate.
hinton (bool, Optional) – Creates a hinton-like plot. Only wors if the provided data is along the cells. Default is False.
data (numpy.ndarray, Optional) – Some data to plot as an 1d or 2d numpy array. Default is None.
title (str, Optional) – Title of the plot. See matplotlib for further details. Default is None.
label (str, Optional) – Title of the plot. See matplotlib for further details. Default is None.
fig (matplotlib.Figure, Optional) – A matplotlib figure to plot on. Default is None.
ax (matplotlib.axes.Axes or a collection of it, Optional.) – A matplotlib axis, or a collection of such objects to plot on. Default is None.
kwargs (dict, Optional) –
The following keyword arguments are understood and forwarded to the appropriate function in matplotlib:
’cmap’ - colormap (if data is provided) ‘lw’ ‘xlim’ ‘ylim’ ‘axis’ ‘suptitle’
fig_kw (dict, Optional) – If there is no figure instance provided, these parameters are forwarded to the
matplotlib.pyplot.figurecall.
Examples
Create a triangulation
>>> from polymesh.grid import grid >>> from polymesh.topo.tr import Q4_to_T3 >>> from polymesh.tri.trimesh import triangulate >>> from dewloosh.mpl import triplot >>> import numpy as np >>> gridparams = { >>> 'size' : (1200, 600), >>> 'shape' : (30, 15), >>> 'eshape' : (2, 2), >>> 'origo' : (0, 0), >>> 'start' : 0 >>> } >>> coordsQ4, topoQ4 = grid(**gridparams) >>> points, triangles = Q4_to_T3(coordsQ4, topoQ4, path='grid') >>> triobj = triangulate(points=points[:, :2], triangles=triangles)[-1]
If you just want to plot the mesh itself, do this
>>> triplot(triobj)
Plot the mesh with random data over the cells
>>> data = np.random.rand(len(triangles)) >>> triplot(triobj, data=data)
>>> data = np.random.rand(len(triangles)) >>> triplot(triobj, hinton=True, data=data)
Plot the mesh with random data over the points
>>> data = np.random.rand(len(points)) >>> triplot(triobj, data=data, cmap='bwr')
You can play with the arguments sent to
matplotlib>>> triplot(triobj, data=data, cmap='Set1', axis='off')
- dewloosh.mpl.parallel.parallel(data, *args, labels=None, padding=0.05, colors=None, lw=0.2, bezier=True, figsize=None, title=None, **kwargs)[source]¶
- Parameters
data (list of arrays) – A list of numpy.ndarray for each column. Each array is 1d with a length of N, where N is the number of data records (the number of lines).
labels (Iterable, Optinal) – Labels for the columns. If provided, it must have the same length as data.
padding (float, Optional) – Controls the padding around the plot.
colors (list of float, Optional) – A value for each record. Default is None.
lw (float, Optional) – Linewidth.
bezier (bool, Optional) – If True, bezier curves are created instead of a linear polinomials. Default is True.
figsize (tuple, Optional) – A tuple to control the size of the figure. Default is None.
title (str, Optional) – The title of the figure.
Example
>>> from dewloosh.mpl import parallel >>> colors = np.random.rand(150, 3) >>> labels = [str(i) for i in range(10)] >>> values = [np.random.rand(150) for i in range(10)] >>> parallel(values, labels=labels, padding=0.05, lw=0.2, >>> colors=colors, title='Parallel Plot with Random Data')
- dewloosh.mpl.parallel.aligned_parallel(data, datapos, *args, yticks=None, labels=None, sharelimits=False, texlabels=None, xticksrotation=0, suptitle=None, slider=False, slider_label=None, hlines=None, vlines=None, y=None, xoffset=0.0, yoffset=0.0, **kwargs)[source]¶
- Parameters
data (numpy.ndarray or dict) – The values to plot. If it is a numpy array, labels must be provided with the argument labels, if it is a sictionary, the keys of the dictionary are used as labels.
datapos (Iterable) – Positions of the provided data values.
yticks (Iterable, Optional) – Positions of ticks on the vertical axes. Default is None.
labels (Iterable, Optional) – An iterable of strings specifying labels for the datasets. Default is None.
sharelimits (bool, Optional) – If True, the axes share limits of the vertical axes. Default is False.
texlabels (Itrable, Optional) – TeX-formatted labels. If provided, it must have the same length as labels. Default is None.
xticksrotation (int, Optional) – Rotation of the ticks along the vertical axes. Expected in degrees. Default is 0.
suptitle (str, Optional) – See Matplotlib’s docs for the details. Default is None.
slider (bool, Optional) – If True, a slider is added to the figure for interactive plots. Default is False.
slider_label (str, Optional) – A label for the slider. Only if slider is true. Default is None.
hlines (Iterable, Optional) – A list of data values where horizontal lines are to be added to the axes. Default is None.
vlines (Iterable, Optional) – A list of data values where vertical lines are to be added to the axes. Default is None.
y (float or int, Optional) – Value for the vertical axis. Default is the average of the limits of the vertical axis (0.5*(datapos[0] + datapos[-1])).
xoffset (float, Optional) – Margin of the plot in the vertical direction. Default is 0.
yoffset (float, Optional) – Margin of the plot in the horizontal direction. Default is 0.
**kwargs (dict, Optional) – Extra keyword arguments are forwarded to the creator of the matplotlib figure. Default is None.
Example
>>> from dewloosh.mpl import aligned_parallel >>> labels = ['a', 'b', 'c'] >>> values = np.array([np.random.rand(150) for _ in labels]).T >>> datapos = np.linspace(-1, 1, 150) >>> aligned_parallel(values, datapos, labels=labels, yticks=[-1, 1])