Source code for locan.visualize.render_mpl.render3d
"""This module provides functions for rendering `LocData` objects in 3D."""from__future__importannotationsimportloggingfromtypingimportTYPE_CHECKING,AnyfrommatplotlibimportpyplotaspltifTYPE_CHECKING:importmatplotlibasmplfromlocan.dataimportLocData__all__:list[str]=["scatter_3d_mpl"]logger=logging.getLogger(__name__)
[docs]defscatter_3d_mpl(locdata:LocData,ax:mpl.axes.Axes|None=None,index:bool=True,text_kwargs:dict[str,Any]|None=None,**kwargs:Any,)->mpl.axes.Axes:""" Scatter plot of locdata elements with text marker for each element. Parameters ---------- locdata Localization data. ax The axes on which to show the plot index Flag indicating if element indices are shown. text_kwargs Keyword arguments for :func:`matplotlib.axes.Axes.text`. kwargs Other parameters passed to :func:`matplotlib.axes.Axes.scatter`. Returns ------- matplotlib.axes.Axes3D Axes object with the image. """iftext_kwargsisNone:text_kwargs={}# Provide matplotlib.axes.Axes if not providedifaxisNone:ax=plt.gca()# return ax if no or single point in locdataiflen(locdata)<2:iflen(locdata)==1:logger.warning("Locdata carries a single localization.")returnaxcoordinates=locdata.coordinatesax.scatter(*coordinates.T,**dict({"marker":"+","color":"grey"},**kwargs))# plot element numberifindex:forcentroid,markerinzip(coordinates,locdata.data.index.values):ax.text(# type:ignore*centroid,marker,**dict({"color":"grey","size":20},**text_kwargs))ax.set(xlabel="position_x",ylabel="position_y",zlabel="position_z")returnax