pytom3d
Submodules
pytom3d.core module
- class pytom3d.core.Topography(name: str = 'unnamed')[source]
Bases:
object- add_points(fxy: callable, std_noise=None) None[source]
Adds a function-generated z-coordinate to the grid points.
Parameters
- fxycallable
A function that takes x and y coordinates and returns z.
- std_noisefloat or None, optional
Standard deviation of Gaussian noise to be added to z (default is None).
Returns
None
- cardinality()[source]
Update the cardinality attribute based on the number of data points.
This method calculates and updates the ‘N’ attribute, representing the cardinality (number of data points) of the object.
Parameters
None
Returns
None
- cut(ax: str = None, lo: float = -inf, up: float = inf, tol=1e-08, out=False) None[source]
Cut data points along a specified axis within a given range.
Parameters
- axstr, optional
The axis to cut along (choose from ‘x’, ‘y’, ‘z’), by default None.
- lofloat, optional
The lower bound for cutting, by default -np.inf.
- upfloat, optional
The upper bound for cutting, by default np.inf.
- tolfloat, optional
The tolerance for considering values close to bounds, by default 1e-8.
- outbool, optional
If True, keep the points outside the specified range, by default False.
Returns
- List[Tuple]
A list containing information about the cut event.
Raises
- KeyError
If the specified axis is not valid.
- ValueError
If the resulting cloud has no points after cutting.
- export(path_to_file: str, filename: str, extension: str = '.csv', delimiter: str = ',') None[source]
Export the grid points to a file in CSV format.
Parameters
- path_to_filestr
The path to the directory where the file will be saved.
- filenamestr
The name of the file (without extension).
- extensionstr, optional
The file extension (default is “.csv”).
- delimiterstr, optional
The delimiter used in the CSV file (default is “,”).
Returns
None
- filter_points(indices: ndarray) List[Tuple][source]
Filter points by index.
Parameters
- indicesnp.ndarray
The vector of indices of the points that are kept in the cloud.
Returns
- List[Tuple]
A list containing information about the filtering event.
- fit(regressor, **args: Dict) None[source]
Fit a regressor to the data.
Parameters
- regressorsklearn regressor class or callable
The regressor to be used for fitting. If a sklearn regressor class is provided, it is instantiated and fitted to the data. If a callable (e.g., a spline function) is provided, it is used directly for fitting.
- **argsadditional keyword arguments
Additional arguments to be passed to the regressor constructor if using a sklearn regressor class.
Notes
This method first tries to fit the provided regressor to the data using the sklearn API. If an AttributeError occurs (indicating that the regressor doesn’t have a ‘fit’ method), it assumes that a callable (e.g., a spline function) is provided and uses it directly for fitting.
Returns
None
Examples
# Example 1: Fit a linear regression model model.fit(LinearRegression())
# Example 2: Fit a custom spline function model.fit(scipy.bisplrep, **args)
- flip(v: ndarray = array([1., 1., 1.])) List[Tuple][source]
Flip the data points along each axis.
Parameters
- vnp.ndarray, optional
The scaling factors along each axis, by default np.array([1., 1., 1.]).
Returns
- List[Tuple]
A list containing information about the flip event.
- get_topography(x, y, z, unc: ndarray = None)[source]
Set the topography data for the object.
This method sets the topography data for the object by updating the ‘P’ attribute with the provided x, y, and z coordinates. It also updates the uncertainty information if provided. Additionally, it calculates and updates the cardinality, edges, and centroid attributes.
Parameters
- xnp.ndarray
X-coordinates of the data points.
- ynp.ndarray
Y-coordinates of the data points.
- znp.ndarray
Z-coordinates of the data points.
- uncnp.ndarray, optional
Uncertainty information associated with the data points, by default None.
Returns
None
- history()[source]
Print the event history.
Prints each recorded event in the history list, displaying key-value pairs.
Returns
None
Notes
Each event is separated by a line of dashes for better readability.
- make_grid(x_bounds: List[float], y_bounds: List[float], x_res: int = 10, y_res: int = 10) None[source]
Initializes the grid within specified x and y bounds with given resolution.
Parameters
- x_boundslist of float
The bounds for the x-axis [x_min, x_max].
- y_boundslist of float
The bounds for the y-axis [y_min, y_max].
- x_resint, optional
The resolution of the grid along the x-axis (default is 10).
- y_resint, optional
The resolution of the grid along the y-axis (default is 10).
Notes
z-value is initialli set to zero.
Returns
None
- pick_points(axis: int, loc: float, tol: float = 0.001) Tuple[ndarray][source]
Pick points based on proximity to a specified location along a given axis.
Parameters
- axisint
The axis along which to pick points. 0 for x-axis, 1 for y-axis.
- locfloat
The location along the specified axis to which points are compared.
- tolfloat, optional
The tolerance value for proximity. Default is 1e-3.
Returns
- picked_locsarray_like
Array of locations of the picked points.
- picked_coordsarray_like
Array of coordinates (along the other axis) of the picked points.
- picked_valuesarray_like
Array of values of the picked points.
- pick_scans(axis: int, loc: float, centre: float = None, lower: float = None, upper: float = None, tol: float = 0.001) Tuple[source]
Pick scans based on proximity to specified locations and bounds.
Parameters
- axisint
The axis along which to pick scans. 0 for x-axis, 1 for y-axis.
- locfloat
The location along the specified axis to which points are compared.
- centrefloat, optional
The central location for the bounding box. If provided, lower and upper must also be provided. Default is None.
- lowerfloat, optional
The lower bound for the bounding box. Used in combination with centre and upper. Default is None.
- upperfloat, optional
The upper bound for the bounding box. Used in combination with centre and lower. Default is None.
- tolfloat, optional
The tolerance value for proximity. Default is 1e-3.
Returns
- scanslist of Scan objects
List of Scan objects picked based on the specified conditions.
- pred(X: ndarray) ndarray[source]
Predict target values for input data.
Parameters
- Xnp.ndarray
Input data for prediction.
Returns
- np.ndarray
If using a sklearn regressor, returns a tuple containing the predicted values and their standard deviations. If using a callable (e.g., a spline function), returns an array of predicted values.
Notes
If an exception occurs during prediction, it assumes that a callable regressor is provided, and uses it directly for prediction.
- read(file_path: str, reader: callable, **reader_args)[source]
Read data from file.
Parameters
- file_pathstr
The path to the file.
- readercallable
A callable pandas reader function to read data from the file.
- **reader_args
Additional arguments to pass to the reader.
Returns
None
- rotate(t_deg: ndarray = array([0., 0., 0.]), rot_mat: ndarray = None) List[Tuple][source]
Rotate the data points about the origin.
Parameters
- t_degnp.ndarray, optional
The rotation angles in degrees around x, y, and z axes, by default np.array([0., 0., 0.]).
- rot_matnp.ndarray, optional
Custom rotation matrix. If provided, t_deg will be ignored, by default None.
Returns
- List[Tuple]
A list containing information about the rotation event.
- rotate_about_centre(c: ndarray = array([0., 0., 0.]), t_deg: ndarray = array([0., 0., 0.]), rot_mat: ndarray = None) List[Tuple][source]
Rotate the data points about a specified center. Wraps translate and rotate.
Parameters
- cnp.ndarray, optional
The center of rotation, by default np.array([0., 0., 0.]).
- t_degnp.ndarray, optional
The rotation angles in degrees around x, y, and z axes, by default np.array([0., 0., 0.]).
- rot_matnp.ndarray, optional
Custom rotation matrix. If provided, t_deg will be ignored, by default None.
Returns
- List[Tuple]
A list containing information about the rotation event.
- rotate_by_svd() None[source]
Rotate the data points using Singular Value Decomposition (SVD).
Wraps translate and rotate via rotate_about_centre.
This method applies rotation to the data points based on the results obtained from Singular Value Decomposition (SVD). It uses the rotate_about_centre method to perform the rotation.
The rotation is achieved by specifying the rotation matrix as Vt obtained from the SVD, and the center of rotation (G) is set as the negative of the centroid of the data points.
Parameters
None
Returns
None
- svd() List[Tuple][source]
Perform Singular Value Decomposition (SVD) on the data points.
Returns
- List[Tuple]
A list containing information about the SVD event.
Notes
The SVD decomposes the data matrix into three matrices U, S, and V, such that P = U * S * V^T.
- translate(v: ndarray = array([0, 0, 0]), aux: bool = False) List[Tuple][source]
Translate the data points by the given vector.
Parameters
- vnp.ndarray, optional
The translation vector, by default np.array([0, 0, 0]).
- auxbool, optional
If True, indicates an auxiliary translation, by default False.
Returns
- List[Tuple]
A list containing information about the translation event.
pytom3d.util module
- pytom3d.util.contour_data_wrapper(path: str, match: str, pop_first=True, take_first=False) Tuple[ndarray][source]
Wrapper function for generating contour data.
Parameters
- pathstr
Path to the directory containing data files.
- matchstr
A string used to match the desired data files.
- pop_firstbool, optional
If True, remove and discard the first element of the resulting list. Default is False.
- take_firstbool, optional
If True, return only the first matching file. Overrides pop_first. Default is False.
Returns
- Tuple[np.ndarray]
A tuple containing the x-coordinates, y-coordinates, mean value, and standard deviation.
- pytom3d.util.export_regressor(regressor, folder: str = './', filename: str = 'my_regressor', extension: str = '.rg', excluded_keys: List[str] = [], forced_values: List[Any] = []) None[source]
Export the attributes of a regressor to a dictionary for storage or inspection.
Parameters
- regressorobject
The regressor object to export.
- path_to_filestr, optional
The path to the file for exporting the regressor attributes. Default is “./”.
- excluded_keyslist of str, optional
A list of attribute keys to be excluded from the exported dictionary.
- forced_valueslist of any, optional
A list of values to be used for attributes specified in excluded_keys.
Returns
The dictionary containing the attributes of the regressor.
Raises
- AssertionError
If the length of excluded_keys is not equal to the length of forced_values.
Notes
This function is provided for convenience to handle backward compatibility of scikit-learn.
- pytom3d.util.gather_data(match: str, inp: List[int], out: int, path: str, *list_path: List[str]) None[source]
Load data from multiple files, extract specified columns, and save to a csv file.
Parameters
- matchstr
A regular expression pattern to match against the file paths.
- inpList[int]
List of column indices to extract as input features.
- outint
Index of the column to extract as the output feature.
- pathstr
Path to the output Excel file.
- *list_pathList[str]
Variable number of file paths containing the data.
Returns
None
- pytom3d.util.get_coordinates(inp: List[int], *list_path: List[str]) ndarray[source]
Load and return the specified columns as coordinates from the first file path provided.
Parameters
- inpList[int]
List of column indices to extract as coordinates.
- list_pathList[str]
Variable number of file paths containing the data. Only the first file path is used.
Returns
- np.ndarray
An array containing the coordinates extracted from the specified columns of the first file.
- pytom3d.util.import_regressor(folder: str = './', filename: str = 'my_regressor.rg', init_regressor=None) dict[source]
Import a regressor’s attributes from a saved file and update an initialized regressor object.
Parameters
- folderstr, optional
The path to the folder containing the saved regressor attributes file. Default is “./”.
- filenamestr, optional
The name of the file containing the saved regressor attributes. Default is “my_regressor.rg”.
- init_regressorobject
The initialized regressor object to be updated with the imported attributes.
Returns
- dict
A dictionary containing the imported regressor attributes.
Notes
This function is provided for convenience to handle backward compatibility of scikit-learn.
- pytom3d.util.list_files(folder: str = './', extension: str = '.gpr') List[str][source]
List files in a folder.
Parameters
- folderstr, optional
Path to the folder to search for files. Default is “./”.
- extensionstr, optional
File extension to filter files. Default is “.gpr”.
Returns
- List[str]
A list of file paths with the specified extension in the folder.
- pytom3d.util.lite_dict(gpr_obj: Any)[source]
Load lite version of the regressor.
Parameters
- gpr_objAny
Object of the Gaussian Process Regressor.
Returns
- Dict[str, Any]
Dictionary containing selected parameters and training data.
Notes
This function loads a lite version of the Gaussian Process Regressor by extracting specific parameters and training data for testing purposes.
- pytom3d.util.load(path: str = './')[source]
Load an object from a binary file using pickle.
Parameters
- path: str, optional
The path of the file. Default is “./”.
Returns
- Any
The loaded object.
- pytom3d.util.predict_at_node(xx, yy, regressor)[source]
Predict the value at a specific node in a regression model.
Parameters
- xxfloat
The x-coordinate of the node.
- yyfloat
The y-coordinate of the node.
- regressornumpy.ndarray
The regression model containing node information.
Returns
- float
The predicted value at the specified node.
Raises
- Exception
If there is not exactly one node matching the specified coordinates.
- pytom3d.util.prediction_wrapper(regressor, x, y) Tuple[ndarray][source]
Predict the target variable and its uncertainty for given x and y coordinates using a regressor.
Parameters
- regressorRegressor
The trained regressor model.
- xfloat
The x-coordinate for prediction.
- yfloat
The y-coordinate for prediction.
Returns
- tuple
A tuple containing the predicted value and its associated standard deviation (uncertainty).
- pytom3d.util.printer(func: callable)[source]
A decorator for class methods that saves a figure if ‘save’ is True.
Borrowed from https://github.com/aletgn/b-fade/blob/master/src/bfade/util.py
This decorator wraps a method that generates a figure and a title, and it saves the figure to the specified location if ‘save’ is True.
Parameters
- funccallable
The function to be decorated, which generates a figure and a title.
Returns
- callable
The decorated function.
- pytom3d.util.recursive_search(path: str, extension: str = '.dat', match: str = None, pop_first: bool = False, take_first: bool = False) List[str][source]
Recursively search for files with a specified extension in a directory and its subdirectories, optionally filtering by a match string and returning a modified list based on flags.
Parameters
- pathstr
The path to the directory to search in.
- extensionstr, optional
The file extension to search for. Default is “.dat”.
- matchstr, optional
A substring to match in the file names. Default is None.
- pop_firstbool, optional
If True, remove and discard the first element of the resulting list. Default is False.
- take_firstbool, optional
If True, return only the first matching file. Overrides pop_first. Default is False.
Returns
- List[str]
A list of file paths matching the specified criteria.
- pytom3d.util.save(obj, folder: str = './', filename: str = 'my_file', extension: str = '.bin') None[source]
Save the given object to a binary file using pickle.
Parameters
- obj: Any
The object to be saved.
- folder: str, optional
The directory path where the file will be saved. Default is “./”.
- filename: str, optional
The name of the file to be saved. Default is “my_file”.
- extension: str, optional
The file extension. Default is “.bin”.
Returns
None
- pytom3d.util.scan_data_wrapper(path: str, match: str, pop_first=True, take_first=False) Tuple[ndarray][source]
Wrapper function for generating scan data.
Parameters
- pathstr
Path to the directory containing data files.
- matchstr
A string used to match the desired data files.
- pop_firstbool, optional
If True, remove and discard the first element of the resulting list. Default is False.
- take_firstbool, optional
If True, return only the first matching file. Overrides pop_first. Default is False.
Returns
- Tuple[np.ndarray]
A tuple containing the x-coordinates, mean value, and standard deviation.
- pytom3d.util.trials(regressor, mesh, n: int = 1, folder: str = './') None[source]
Generate and save trial data using a Gaussian Process Regression model.
Parameters
- regressor :
The regressor of the topography.
- meshTopography
The topogrphy object containing mesh data points for prediction.
- nint, optional
Number of trials to generate (default is 1).
- folderstr, optional
The folder path to save the trial data files (default is “./”).
Returns
None
- pytom3d.util.update(method: callable)[source]
Decorator to update edges, centroid, cardinality, and record history after executing a method.
Parameters
- methodcallable
The method to be decorated.
Returns
- callable
Decorated method.
Notes
This decorator assumes that the decorated method returns a list of tuples, where each tuple contains key-value pairs to be recorded in the event history.
pytom3d.viewer module
- class pytom3d.viewer.PostViewer(**kwargs)[source]
Bases:
object- config(save: bool = False, folder: str = './', fmt: str = 'png', dpi: int = 300) None[source]
Configure settings for saving plots.
Borrowed from https://github.com/aletgn/b-fade/
Parameters
- savebool, optional
Flag indicating whether to save plots. The default is False.
- folderstr, optional
Folder path where plots will be saved. The default is “./”.
- fmtstr, optional
Format for saving plots. The default is “png”.
- dpiint, optional
Dots per inch for saving plots. The default is 300.
Returns
None
- config_canvas(cmap: str = 'RdYlBu_r', levels: int = 8, x_lim: List[float] = [-100, 100], y_lim_top: List[float] = [10, 20], y_lim_bot: List[float] = [-10, -20], y_lim_scan: str = [-140, 140], cbar_lim: List[float] = [-140, 140], loc: str = 'best', bbox_to_anchor: List[float] = None) None[source]
Configure canvas for plotting.
Parameters
- cmapstr, optional
Colormap to use for plotting. Default is “RdYlBu_r”.
- levelsint, optional
Number of levels for the colorbar. Default is 8.
- x_limList[float], optional
Limits for the x-axis. Default is [-100, 100].
- y_lim_topList[float], optional
Limits for the top part of the y-axis. Default is [10, 20].
- y_lim_botList[float], optional
Limits for the bottom part of the y-axis. Default is [-10, -20].
- y_lim_scanList[float], optional
Limits for the y-axis for scan data. Default is [-140, 140].
- cbar_limList[float], optional
Limits for the color bar. Default is [-140, 140].
- locstr, optional
Location of the legend. Default is “best”.
- bbox_to_anchorList[float], optional
Anchor point for the legend bounding box. Default is None.
Returns
- None
This function does not return anything. It only sets instance attributes.
- config_colourbar(top=None, bot=None) None[source]
Configure color bar limits based on top and bottom bounds.
Parameters
- topTuple
Tuple containing data for the top bounds. It should contain the mean and standard deviation.
- botTuple
Tuple containing data for the bottom bounds. It should contain the mean and standard deviation.
Returns
- None
This function does not return anything. It only sets the instance attributes for color bar limits.
- config_scan_view(xlabel='$x$ [mm]', ylabel='$y$ [mm]', x_lim=[-20, 20], y_lim=[-70, 70], legend_config=None)[source]
- contour(top_cnt, bot_cnt, cbarlabeltop: str = 'Expected Value', cbarlabelbot: str = 'Uncertainty') Tuple[source]
Create contour plots for the provided data.
Parameters
- top_cntTopography object
Data for the top contour plot.
- bot_cntTopography object
Data for the bottom contour plot.
- cbarlabeltopstr
Label of the top colour bar
- cbarlabelbotstr
Label of the bot colour bar
Returns
- figFigure
The matplotlib figure object.
- namestr
The name associated with the plot.
- contour_and_scan_2(top_cnt, bot_cnt, top_scan=None, bot_scan=None, top_err=None, bot_err=None) None[source]
Plot contour and scan data.
Parameters
- top_cntobject
Object containing data for the top contours.
- bot_cntobject
Object containing data for the bottom contours.
- top_scanobject, optional
Object containing data for the top scan. Default is None.
- bot_scanobject, optional
Object containing data for the bottom scan. Default is None.
- top_errobject, optional
Object containing data for the top scan. Default is None.
- bot_errobject, optional
Object containing data for the bottom scan. Default is None.
Returns
- None
This function does not return anything. It only displays the plot.
- scan_compare(fills: List, bars: List, regular: List = None, strip: Dict = None) Tuple[source]
Compare scans by plotting filled regions and error bars.
Parameters
- fillslist of scans
List of data for the filled regions.
- barslist of scans
List of data for the error bars.
- regularlist of scans
List of data for without fills and bars. The default is None
Returns
- figFigure
The matplotlib figure object.
- namestr
The name associated with the plot.
- stripDict
Dictionary containing the information to draw a strip over the plot.
Example
- strip = {“xs”: [-10, 10], “label”: “FILL”, “color”: “grey”, “alpha”: 0.2,
“labelleft”: “LEFT”, “labelright”: “RIGHT”, “epsh”: 5, “epsv”: 10}
- scan_view(swap: bool = False, *scan: List) None[source]
Plot scan data.
Parameters
- swapbool, optional
If True, swap x and y axes in the plot. Default is False.
- *scanList
List of scan data to plot. Each scan data should be provided as a list-like object.
Returns
None
- scan_view_and_bar(swap: bool = False, strip: Dict = None, *scan: List) None[source]
Plot scan data with error bars.
Parameters
- swapbool, optional
If True, swap x and y axes in the plot. Default is False.
- scanList
List of scan data to plot. Each scan data should be provided as a list-like object.
- stripDict
Dictionary containing the information to draw a strip over the plot.
Example
- strip = {“xs”: [-10, 10], “label”: “FILL”, “color”: “grey”, “alpha”: 0.2,
“labelleft”: “LEFT”, “labelright”: “RIGHT”, “epsh”: 5, “epsv”: 10}
Returns
None
- scan_view_and_fill(swap: bool = False, *scan: List) None[source]
Plot scan data with filled error regions.
Parameters
- swapbool, optional
If True, swap x and y axes in the plot. Default is False.
- *scanList
List of scan data to plot. Each scan data should be provided as a list-like object.
Returns
None
- class pytom3d.viewer.Viewer(name: str = 'unnamed')[source]
Bases:
object- config(save: bool = False, folder: str = './', fmt: str = 'png', dpi: int = 300) None[source]
Configure settings for saving plots.
Borrowed from https://github.com/aletgn/b-fade/
Parameters
- savebool, optional
Flag indicating whether to save plots. The default is False.
- folderstr, optional
Folder path where plots will be saved. The default is “./”.
- fmtstr, optional
Format for saving plots. The default is “png”.
- dpiint, optional
Dots per inch for saving plots. The default is 300.
Returns
None
- config_3d(point_size: float = 0.3, cmap: str = 'RdYlBu_r', xlabel: str = '$x_g$ [mm]', ylabel: str = '$y_g$ [mm]', zlabel: str = '$u(x_g, y_g)$ [mm]', cbarlabel: str = 'Aux', x_lim: List = [-110, 110], y_lim: List = [-38, 38], z_lim: List = None, zticks: int = 10, zoom: float = 1) None[source]
Configure the 3D plot parameters.
Parameters
- point_sizefloat, optional
Size of the points in the plot (default is 0.3).
- cmapstr, optional
Colormap for the plot (default is “RdYlBu_r”).
- xlabelstr, optional
Label for the x-axis (default is r’$x_g$ [mm]’).
- ylabelstr, optional
Label for the y-axis (default is r’$y_g$ [mm]’).
- zlabelstr, optional
Label for the z-axis (default is r’$u(x_g, y_g)$ [mm]’).
- cbarlabelstr, optional
Label for the colourbar (default is ‘Aux’).
- x_limlist of int, optional
Limits for the x-axis (default is [-110, 110]).
- y_limlist of int, optional
Limits for the y-axis (default is [-38, 38]).
- z_limlist of int or None, optional
Limits for the z-axis (default is None).
- zticksint, optional
Number of ticks on the z-axis (default is 10).
- zoomfloat, optional
Zoom level for the plot (default is 1).
Returns
None
- scatter3D(*data: List[Topography]) None[source]
Generate a 3D scatter plot for the given Topography data.
Parameters
- dataList[Topography]
A list of Topography objects for which a 3D scatter plot will be generated.
- x_limList[float], optional
Limits for the x-axis. Default is None.
- y_limList[float], optional
Limits for the y-axis. Default is None.
- z_limList[float], optional
Limits for the z-axis. Default is None.
Returns
None
- scatter3DRegression(regression: Topography, reference: Topography = None) None[source]
- scatter3DRegressorUnc(*data: List)[source]
Create a 3D scatter plot of the regressor uncertainties.
Parameters
- dataList
Set of Topographies.
Returns
- matplotlib.figure.Figure
The created figure.
- str
The name of the plot.
- set_limits(x: List[float] = None, y: List[float] = None, z: List[float] = None) None[source]
Set the limits for the x, y, and z axes.
Parameters
- xList[float], optional
The limits for the x-axis.
- yList[float], optional
The limits for the y-axis.
- zList[float], optional
The limits for the z-axis.
Returns
None
- views2D(*data: List[Topography]) None[source]
Generate 2D scatter plots for the XY, XZ, and YZ planes of multiple Topography objects.
Parameters
- dataList[Topography]
A list of Topography objects for which 2D scatter plots will be generated.
Returns
None
- pytom3d.viewer.cbar_bounds(v: ndarray, w: ndarray) Tuple[float][source]
Calculate the lower and upper bounds for color bar.
Parameters
- vnp.ndarray
First array for comparison.
- wnp.ndarray
Second array for comparison.
Returns
- Tuple[float]
A tuple containing the lower and upper bounds for the color bar.
- pytom3d.viewer.cfg_matplotlib(font_size: int = 12, font_family: str = 'sans-serif', use_latex: bool = False, interactive: bool = False) None[source]
Set Matplotlib RC parameters for font size, font family, and LaTeX usage.
Borrowed from https://github.com/aletgn/b-fade/blob/master/src/bfade/util.py
Parameters
- font_sizeint, optional
Font size. The default is 12.
- font_familystr, optional
Font family. The default is ‘sans-serif’.
- use_latexbool, optional
Enable LaTeX text rendering. The default is False.
- interactive: bool, optional
Whether to keep matplotlib windows open.
Returns
None
- pytom3d.viewer.discrete_colorbar(cmap: str, lower_bound: float, upper_bound: float, levels: int) Tuple[_ScalarMappable, BoundaryNorm][source]
Create a discrete colorbar with custom colormap and bounds.
Parameters
- cmapstr
Name of the colormap to use.
- lower_boundfloat
Lower bound for the colorbar.
- upper_boundfloat
Upper bound for the colorbar.
- levelsint
Number of discrete levels for the colorbar.
Returns
- Tuple[plt.ScalarMappable, BoundaryNorm]
A tuple containing the ScalarMappable object for mapping scalar data to colors, and the BoundaryNorm object for normalizing scalar data to the colormap’s range.