AFL.double_agent.plotting module#
Visualization tools for materials composition and phase data.
This module provides plotting utilities for visualizing compositional data and phase diagrams. It supports both 2D, 3D and ternary plots using matplotlib, with special handling for labeled data and phase regions.
Key features: - Support for 2D, 3D and ternary plots - Surface and scatter plot styles - Automatic handling of phase labels - Flexible customization through matplotlib parameters - Integration with xarray data structures
- AFL.double_agent.plotting.plot(dataset: Dataset, kind: str = 'scatter', backend: str = 'mpl', **kwargs) List[Artist] | Dict[str, Any] #
Master plotting function that dispatches to specialized plotting functions.
This function serves as a unified interface for all plotting functions in the module. It dispatches to the appropriate specialized function based on the plottype and backend.
- Parameters:
dataset (xr.Dataset) – Dataset containing the data to plot
plottype (str, default='scatter') – Type of plot to create. Options: - ‘scatter’: Scatter plot of compositional data - ‘surface’: Surface plot of compositional data - ‘sas’: Small-angle scattering plot
backend (str, default='mpl') – Plotting backend to use. Options: - ‘mpl’: Matplotlib - ‘plotly’: Plotly
**kwargs (dict) – Additional keyword arguments passed to the specialized plotting function. See the documentation of the specialized functions for details.
- Returns:
The return value of the specialized plotting function, which is either a list of matplotlib artists or a plotly figure object.
- Return type:
Union[List[plt.Artist], Dict[str, Any]]
- Raises:
ValueError – If an invalid plottype or backend is specified.
Examples
>>> # Create a scatter plot using matplotlib >>> plot(dataset, plottype='scatter', backend='mpl', ... component_variable='compositions', labels='labels')
>>> # Create a surface plot using plotly >>> plot(dataset, plottype='surface', backend='plotly', ... component_variable='compositions', ternary=True)
>>> # Create a small-angle scattering plot using matplotlib >>> plot(dataset, plottype='sas', backend='mpl', ... plot_type='loglog', x='q', y='intensity')
- AFL.double_agent.plotting.plot_sas_mpl(dataset: Dataset, plot_type: str = 'loglog', x: str = 'q', y: str = None, ylabel: str = 'Intensity [A.U.]', xlabel: str = 'q [$Å^{-1}$]', legend: bool = True, base: float = 10, waterfall: bool = False, clean_params: dict = None, **mpl_kw) List[Artist] #
Create a plot of small-angle scattering data using matplotlib.
Generates a plot of scattering data with various options for visualization, including log-log plots, waterfalls.
- Parameters:
dataset (xr.Dataset) – Dataset containing scattering data
plot_type (str, default='loglog') – Type of plot to create. Options: - ‘loglog’: Log-log plot - ‘linlin’: Linear-linear plot - ‘logwaterfall’: Log waterfall plot - ‘waterfall’: Linear waterfall plot
x (str, default='q') – Name of the x-axis variable
y (str, default=None) – Name of the y-axis variable. If None, will use the first data variable that isn’t x.
ylabel (str, default='Intensity [A.U.]') – Label for the y-axis
xlabel (str, default='q [$Å^{-1}$]') – Label for the x-axis
legend (bool, default=True) – Whether to show a legend
base (float, default=10) – Base for waterfall plots
waterfall (bool, default=False) – Whether to create a waterfall plot (overrides plot_type)
**mpl_kw (dict) – Additional keyword arguments passed to matplotlib’s plotting functions
- Returns:
List of created matplotlib artists
- Return type:
List[plt.Artist]
- AFL.double_agent.plotting.plot_sas_plotly(dataset: Dataset, plot_type: str = 'loglog', x: str = 'q', y: str = None, ylabel: str = 'Intensity [A.U.]', xlabel: str = 'q [$Å^{-1}$]', legend: bool = True, base: float = 10, waterfall: bool = False, **plotly_kw) Dict[str, Any] #
Create a plot of small-angle scattering data using Plotly.
Generates an interactive plot of scattering data with various options for visualization, including log-log plots, waterfalls, and data cleaning.
- Parameters:
dataset (xr.Dataset) – Dataset containing scattering data
plot_type (str, default='loglog') – Type of plot to create. Options: - ‘loglog’: Log-log plot - ‘linlin’: Linear-linear plot - ‘logwaterfall’: Log waterfall plot - ‘waterfall’: Linear waterfall plot
x (str, default='q') – Name of the x-axis variable
y (str, default=None) – Name of the y-axis variable. If None, will use the first data variable that isn’t x.
ylabel (str, default='Intensity [A.U.]') – Label for the y-axis
xlabel (str, default='q [$Å^{-1}$]') – Label for the x-axis
legend (bool, default=True) – Whether to show a legend
base (float, default=10) – Base for waterfall plots
waterfall (bool, default=False) – Whether to create a waterfall plot (overrides plot_type)
**plotly_kw (dict) –
clean_params (dict, default=None) – Parameters for data cleaning. Options include: - qlo: Lower q limit - qhi: Upper q limit - qlo_isel: Lower q index - qhi_isel: Upper q index - pedestal: Pedestal value - npts: Number of points - derivative: Derivative order - sgf_window_length: Savitzky-Golay filter window length - sgf_polyorder: Savitzky-Golay filter polynomial order - apply_log_scale: Whether to apply log scale
**plotly_kw – Additional keyword arguments passed to plotly’s plotting functions
- Returns:
Plotly figure object
- Return type:
Dict[str, Any]
- AFL.double_agent.plotting.plot_scatter_mpl(dataset: Dataset, component_variable: str, component_dim: str = 'component', labels: str | None | List = None, discrete_labels: bool = True, set_axes_labels: bool = True, ternary: bool = False, **mpl_kw) List[Artist] #
Create a scatter plot of compositional data using matplotlib.
Generates a scatter plot of compositional data, supporting both 2D Cartesian and ternary plots. Points can be colored and marked according to phase labels or other values.
- Parameters:
dataset (xr.Dataset) – Dataset containing compositional data and optional labels
component_variable (str) – Name of the variable containing component coordinates
component_dim (str, default='component') – Name of the dimension containing component names
labels (Union[Optional[str], List], default=None) – Labels for coloring points. Can be: - None: Will try to use ‘labels’ from dataset - str: Name of variable in dataset containing labels - List: Direct list of label values
discrete_labels (bool, default=True) – Whether to treat labels as discrete categories (True) or continuous values (False)
set_axes_labels (bool, default=True) – Whether to set axis labels using component names
ternary (bool, default=False) – Whether to create a ternary plot for 3-component data. If False with 3 components, will create a 3D plot using matplotlib’s 3D projection.
**mpl_kw (dict) – Additional keyword arguments passed to matplotlib’s scatter
- Returns:
List of created matplotlib artists
- Return type:
List[plt.Artist]
- Raises:
ValueError – If number of components is not 2 or 3
ImportError – If mpltern is not installed for ternary plots
Notes
When discrete_labels is True, different marker styles are used for each unique label value, cycling through a predefined set of markers.
- AFL.double_agent.plotting.plot_scatter_plotly(dataset: Dataset, component_variable: str, component_dim: str = 'component', labels: str | None | List = None, discrete_labels: bool = True, set_axes_labels: bool = True, ternary: bool = False, **plotly_kw) Dict[str, Any] #
Create a scatter plot of compositional data using Plotly.
Generates an interactive scatter plot of compositional data, supporting both 2D Cartesian, 3D, and ternary plots. Points can be colored and marked according to phase labels or other values.
- Parameters:
dataset (xr.Dataset) – Dataset containing compositional data and optional labels
component_variable (str) – Name of the variable containing component coordinates
component_dim (str, default='component') – Name of the dimension containing component names
labels (Union[Optional[str], List], default=None) – Labels for coloring points. Can be: - None: Will try to use ‘labels’ from dataset - str: Name of variable in dataset containing labels - List: Direct list of label values
discrete_labels (bool, default=True) – Whether to treat labels as discrete categories (True) or continuous values (False)
set_axes_labels (bool, default=True) – Whether to set axis labels using component names
ternary (bool, default=False) – Whether to create a ternary plot for 3-component data. If False with 3 components, will create a 3D plot.
**plotly_kw (dict) – Additional keyword arguments passed to plotly’s plotting functions
- Returns:
Plotly figure object
- Return type:
Dict[str, Any]
- Raises:
ValueError – If number of components is not 2 or 3
ImportError – If plotly is not installed
Notes
When discrete_labels is True, different marker symbols are used for each unique label value, cycling through a predefined set of markers.
- AFL.double_agent.plotting.plot_surface_mpl(dataset: Dataset, component_variable: str, component_dim: str = 'component', labels: str | None | List = None, set_axes_labels: bool = True, ternary: bool = False, **mpl_kw) List[Artist] #
Create a surface plot of compositional data using matplotlib.
Generates a filled surface plot of compositional data, supporting both 2D Cartesian and ternary plots. The surface is colored according to phase labels or other specified values.
- Parameters:
dataset (xr.Dataset) – Dataset containing compositional data and optional labels
component_variable (str) – Name of the variable containing component coordinates
component_dim (str, default='component') – Name of the dimension containing component names
labels (Union[Optional[str], List], default=None) – Labels for coloring the surface. Can be: - None: Will try to use ‘labels’ from dataset - str: Name of variable in dataset containing labels - List: Direct list of label values
set_axes_labels (bool, default=True) – Whether to set axis labels using component names
ternary (bool, default=False) – Whether to create a ternary plot for 3-component data. If False with 3 components, will create a 3D plot using matplotlib’s 3D projection.
**mpl_kw (dict) – Additional keyword arguments passed to matplotlib’s plotting functions
- Returns:
List of created matplotlib artists
- Return type:
List[plt.Artist]
- Raises:
ValueError – If number of components is not 2 or 3
ImportError – If mpltern is not installed for ternary plots
- AFL.double_agent.plotting.plot_surface_plotly(dataset: Dataset, component_variable: str, component_dim: str = 'component', labels: str | None | List = None, set_axes_labels: bool = True, ternary: bool = False, **plotly_kw) Dict[str, Any] #
Create a surface plot of compositional data using Plotly.
Generates an interactive filled surface plot of compositional data, supporting both 2D Cartesian, 3D, and ternary plots. The surface is colored according to phase labels or other specified values.
- Parameters:
dataset (xr.Dataset) – Dataset containing compositional data and optional labels
component_variable (str) – Name of the variable containing component coordinates
component_dim (str, default='component') – Name of the dimension containing component names
labels (Union[Optional[str], List], default=None) – Labels for coloring the surface. Can be: - None: Will try to use ‘labels’ from dataset - str: Name of variable in dataset containing labels - List: Direct list of label values
set_axes_labels (bool, default=True) – Whether to set axis labels using component names
ternary (bool, default=False) – Whether to create a ternary plot for 3-component data. If False with 3 components, will create a 3D plot.
**plotly_kw (dict) – Additional keyword arguments passed to plotly’s plotting functions
- Returns:
Plotly figure object
- Return type:
Dict[str, Any]
- Raises:
ValueError – If number of components is not 2 or 3
ImportError – If plotly is not installed