K3dField#

class discretisedfield.plotting.K3dField(data)#

K3d plotting.


Methods

__dir__

Default dir() implementation.

__eq__

Return self==value.

__repr__

Return repr(self).

nonzero

k3d plot of non-zero discretisation cells.

scalar

k3d plot of a scalar field.

vector

k3d plot of a vector field.


__dir__()#

Default dir() implementation.

nonzero(plot=None, color=5010096, multiplier=None, interactive_field=None, **kwargs)#

k3d plot of non-zero discretisation cells.

If plot is not passed, k3d.Plot object is created automatically. The colour of the non-zero discretisation cells can be specified using color argument.

It is often the case that the object size is either small (e.g. on a nanoscale) or very large (e.g. in units of kilometers). Accordingly, multiplier can be passed as \(10^{n}\), where \(n\) is a multiple of 3 (…, -6, -3, 0, 3, 6,…). According to that value, the axes will be scaled and appropriate units shown. For instance, if multiplier=1e-9 is passed, all axes will be divided by \(1\\,\\text{nm}\) and \(\\text{nm}\) units will be used as axis labels. If multiplier is not passed, the best one is calculated internally.

For interactive plots the field itself, before being sliced with the field, must be passed as interactive_field. For example, if field.x.sel(z=(0, 1)) is plotted, interactive_field=field must be passed. In addition, k3d.plot object cannot be created internally and it must be passed and displayed by the user.

This method is based on k3d.voxels, so any keyword arguments accepted by it can be passed (e.g. wireframe).

Parameters:
  • plot (k3d.Plot, optional) – Plot to which the plot is added. Defaults to None - plot is created internally. This is not true in the case of an interactive plot, when plot must be created externally.

  • color (int, optional) – Colour of the non-zero discretisation cells. Defaults to the default color palette.

  • multiplier (numbers.Real, optional) – Axes multiplier. Defaults to None.

  • interactive_field (discretisedfield.Field, optional) – The whole field object (before any slices) used for interactive plots. Defaults to None.

Raises:

ValueError – If the dimension of the field is not 1.

Examples

  1. Visualising non-zero discretisation cells using k3d.

>>> import discretisedfield as df
...
>>> p1 = (-50e-9, -50e-9, -50e-9)
>>> p2 = (50e-9, 50e-9, 50e-9)
>>> n = (10, 10, 10)
>>> mesh = df.Mesh(region=df.Region(p1=p1, p2=p2), n=n)
>>> field = df.Field(mesh, nvdim=3, value=(1, 2, 0))
>>> def normfun(point):
...     x, y, z = point
...     if x**2 + y**2 < 30**2:
...         return 1
...     else:
...         return 0
>>> field.norm = normfun
...
>>> field.norm.k3d.nonzero()
Plot(...)

See also

voxels()

scalar(plot=None, filter_field=None, cmap='cividis', multiplier=None, interactive_field=None, **kwargs)#

k3d plot of a scalar field.

If plot is not passed, k3d.Plot object is created automatically. The colormap can be specified using cmap argument. By passing filter_field the points at which the voxels are not shown can be determined. More precisely, only those discretisation cells where filter_field != 0 are plotted.

It is often the case that the object size is either small (e.g. on a nanoscale) or very large (e.g. in units of kilometers). Accordingly, multiplier can be passed as \(10^{n}\), where \(n\) is a multiple of 3 (…, -6, -3, 0, 3, 6,…). According to that value, the axes will be scaled and appropriate units shown. For instance, if multiplier=1e-9 is passed, all axes will be divided by \(1\,\text{nm}\) and \(\text{nm}\) units will be used as axis labels. If multiplier is not passed, the best one is calculated internally.

For interactive plots the field itself, before being sliced with the field, must be passed as interactive_field. For example, if field.x.sel(z=(0, 1)) is plotted, interactive_field=field must be passed. In addition, k3d.plot object cannot be created internally and it must be passed and displayed by the user.

This method is based on k3d.voxels, so any keyword arguments accepted by it can be passed (e.g. wireframe).

Parameters:
  • plot (k3d.Plot, optional) – Plot to which the plot is added. Defaults to None - plot is created internally. This is not true in the case of an interactive plot, when plot must be created externally.

  • filter_field (discretisedfield.Field, optional) – Scalar field. Only discretisation cells where filter_field != 0 are shown. Defaults to None.

  • cmap (str, optional) – Colormap.

  • multiplier (numbers.Real, optional) – Axes multiplier. Defaults to None.

  • interactive_field (discretisedfield.Field, optional) – The whole field object (before any slices) used for interactive plots. Defaults to None.

Raises:

ValueError – If the dimension of the field is not 1.

Example

  1. Plot the scalar field using k3d.

>>> import discretisedfield as df
...
>>> p1 = (-50, -50, -50)
>>> p2 = (50, 50, 50)
>>> n = (10, 10, 10)
>>> mesh = df.Mesh(p1=p1, p2=p2, n=n)
...
>>> field = df.Field(mesh, nvdim=1, value=5)
>>> field.k3d.scalar()
Plot(...)

See also

vector()

vector(plot=None, color_field=None, cmap='cividis', head_size=1, points=True, point_size=None, vector_multiplier=None, multiplier=None, interactive_field=None, **kwargs)#

k3d plot of a vector field.

If plot is not passed, k3d.Plot object is created automatically. By passing color_field vectors are coloured according to the values of that field. The colormap can be specified using cmap argument. The head size of vectors can be changed using head_size. The size of the plotted vectors is computed automatically in order to fit the plot. However, it can be adjusted using vector_multiplier.

By default both vectors and points, corresponding to discretisation cell coordinates, are plotted. They can be removed from the plot by passing points=False. The size of the points are calculated automatically, but it can be adjusted with point_size.

It is often the case that the object size is either small (e.g. on a nanoscale) or very large (e.g. in units of kilometers). Accordingly, multiplier can be passed as \(10^{n}\), where \(n\) is a multiple of 3 (…, -6, -3, 0, 3, 6,…). According to that value, the axes will be scaled and appropriate units shown. For instance, if multiplier=1e-9 is passed, all axes will be divided by \(1\,\text{nm}\) and \(\text{nm}\) units will be used as axis labels. If multiplier is not passed, the best one is calculated internally.

For interactive plots the field itself, before being sliced with the field, must be passed as interactive_field. For example, if field.sel(z=(0, 1)) is plotted, interactive_field=field must be passed. In addition, k3d.plot object cannot be created internally and it must be passed and displayed by the user.

This method is based on k3d.voxels, so any keyword arguments accepted by it can be passed (e.g. wireframe).

Parameters:
  • plot (k3d.Plot, optional) – Plot to which the plot is added. Defaults to None - plot is created internally. This is not true in the case of an interactive plot, when plot must be created externally.

  • color_field (discretisedfield.Field, optional) – Scalar field. Vectors are coloured according to the values of color_field. Defaults to None.

  • cmap (str, optional) – Colormap.

  • head_size (int, optional) – The size of vector heads. Defaults to None.

  • points (bool, optional) – If True, points are shown together with vectors. Defaults to True.

  • point_size (int, optional) – The size of the points if shown in the plot. Defaults to None.

  • vector_multiplier (numbers.Real, optional) – All vectors are divided by this value before being plotted. Defaults to None.

  • multiplier (numbers.Real, optional) – Axes multiplier. Defaults to None.

  • interactive_field (discretisedfield.Field, optional) – The whole field object (before any slices) used for interactive plots. Defaults to None.

Raises:

ValueError – If the dimension of the field is not 3.

Examples

  1. Visualising the vector field using k3d.

>>> import discretisedfield as df
...
>>> p1 = (0, 0, 0)
>>> p2 = (100, 100, 100)
>>> n = (10, 10, 10)
>>> mesh = df.Mesh(p1=p1, p2=p2, n=n)
>>> field = df.Field(mesh, nvdim=3, value=(0, 0, 1))
...
>>> field.k3d.vector()
Plot(...)