rofunc.utils.visualab.utils#

1.  Module Contents#

1.1.  Classes#

Frame

A Matplotlib artist that displays a frame represented by its basis.

1.2.  Functions#

set_axis

Set the axis of the figure.

save_img

Save the figure to the specified directory.

make_3d_axis

Generate new 3D axis for plotting the basis.

plot_basis

Plot basis of a rotation matrix.

1.3.  API#

rofunc.utils.visualab.utils.set_axis(ax, data=None, labels=None, elev=45, azim=45, roll=0)[source]#

Set the axis of the figure.

Example:

>>> import rofunc as rf
>>> import numpy as np
>>> fig = plt.figure()
>>> ax = fig.add_subplot(111, projection='3d')
>>> data = [np.array([0, 1, 2]), np.array([0, 1, 2]), np.array([0, 1, 2])]
>>> rf.visualab.set_axis(ax, data)
>>> plt.show()
Parameters:
  • ax – the axis of the figure

  • data – the data to be plotted, used for setting the range of the axis, should be a list 【X, Y, Z】

  • labels – the labels of the axis

  • elev – the elevation of the axis

  • azim – the azimuth of the axis

  • roll – the roll of the axis

rofunc.utils.visualab.utils.save_img(fig, save_dir, fig_name=None, dpi=300, transparent=False, format=None)[source]#

Save the figure to the specified directory.

Parameters:
  • fig – the figure to be saved

  • save_dir – the directory to save the figure

  • fig_name – the name of the figure, if None, the name will be fig_{nb_files}

  • dpi – the dpi of the figure

  • transparent – transparent or not

  • format – the format of the figure, default [‘eps’, ‘png’] together with the same name

Returns:

class rofunc.utils.visualab.utils.Frame(A2B, label=None, s=1.0, **kwargs)[source]#

Bases: matplotlib.artist.Artist

A Matplotlib artist that displays a frame represented by its basis.

A2Barray-like, shape (4, 4)

Transform from frame A to frame B

labelstr, optional (default: None)

Name of the frame

sfloat, optional (default: 1)

Length of basis vectors

draw_label_indicatorbool, optional (default: True)

Controls whether the line from the frame origin to frame label is drawn.

Other arguments except ‘c’ and ‘color’ are passed on to Line3D.

Initialization

set_data(A2B, label=None)[source]#

Set the transformation data.

A2Barray-like, shape (4, 4)

Transform from frame A to frame B

labelstr, optional (default: None)

Name of the frame

draw(renderer, *args, **kwargs)[source]#

Draw the artist.

add_frame(axis)[source]#

Add the frame to a 3D axis.

rofunc.utils.visualab.utils.make_3d_axis(ax_s, pos=111, unit=None, n_ticks=5)[source]#

Generate new 3D axis for plotting the basis.

Parameters:
  • ax_s – Scaling of the new matplotlib 3d axis

  • pos – Position indicator (nrows, ncols, plot_number)

  • unit – Unit of axes. For example, ‘m’, ‘cm’, ‘km’, … The unit will be shown in the axis label, for example, as ‘X [m]’.

  • n_ticks – Number of ticks on each axis

Returns:

New axis

rofunc.utils.visualab.utils.plot_basis(ax=None, R=None, p=np.zeros(3), s=1.0, ax_s=1, strict_check=True, **kwargs)[source]#

Plot basis of a rotation matrix.

Parameters:
  • ax – the axis to plot the basis

  • R – rotation matrix, each column contains a basis vector

  • p – offset from the origin

  • s – scaling of the frame that will be drawn

  • ax_s – scaling of the new matplotlib 3d axis

  • strict_check – raise a ValueError if the rotation matrix is not numerically close enough to a real rotation matrix. Otherwise, we print a warning.

  • kwargs – additional arguments for the plotting functions, e.g. alpha

Returns:

ax