Skip to content

Distributions (polykin.distributions)¤

plotdists ¤

plotdists(
    dists: list[Distribution],
    kind: Literal["number", "mass", "gpc"],
    title: Optional[str] = None,
    **kwargs
) -> Figure

Plot a list of distributions in a joint plot.

PARAMETER DESCRIPTION
dists

List of distributions to be ploted together.

TYPE: list[Distribution]

kind

Kind of distribution.

TYPE: Literal['number', 'mass', 'gpc']

title

Title of plot.

TYPE: str | None DEFAULT: None

RETURNS DESCRIPTION
Figure

Matplotlib Figure object holding the joint plot.

Examples:

>>> from polykin.distributions import Flory, LogNormal, plotdists
>>> a = Flory(100, M0=0.050, name='A')
>>> b = LogNormal(100, PDI=3., M0=0.050, name='B')
>>> fig = plotdists([a, b], kind='gpc', xrange=(1, 1e4), cdf=2)
>>> fig.show()
Source code in src/polykin/distributions/base.py
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
def plotdists(dists: list[Distribution],
              kind: Literal['number', 'mass', 'gpc'],
              title: Optional[str] = None,
              **kwargs
              ) -> Figure:
    """Plot a list of distributions in a joint plot.

    Parameters
    ----------
    dists : list[Distribution]
        List of distributions to be ploted together.
    kind : Literal['number', 'mass', 'gpc']
        Kind of distribution.
    title : str | None
        Title of plot.

    Returns
    -------
    Figure
        Matplotlib Figure object holding the joint plot.

    Examples
    --------
    >>> from polykin.distributions import Flory, LogNormal, plotdists
    >>> a = Flory(100, M0=0.050, name='A')
    >>> b = LogNormal(100, PDI=3., M0=0.050, name='B')
    >>> fig = plotdists([a, b], kind='gpc', xrange=(1, 1e4), cdf=2)
    >>> fig.show()
    """

    # Check input
    kind = Distribution._verify_kind(kind)

    # Create matplotlib objects
    fig, ax = plt.subplots(1, 1)
    if kwargs.get('cdf', 1) == 2:
        ax.twinx()

    # Title
    if title is None:
        titles = {'number': 'Number', 'mass': 'Mass', 'gpc': 'GPC'}
        title = f"{titles.get(kind,'')} distributions"
    fig.suptitle(title)

    # Draw plots sequentially
    for d in dists:
        d.plot(kind=kind, axes=fig.axes, **kwargs)

    return fig