psy_strat.stratplot module

Module to create new stratigraphic plots

This module defines the stratplot() function that can be used to create stratigraphic plots such as pollen diagrams

Classes

StackedGroup(arrays[, bbox, use_weakref, group])

A grouper for stacked plots

StratAllInOne(arrays[, bbox, use_weakref, group])

A StratGroup for single plots

StratGroup(arrays[, bbox, use_weakref, group])

Base class for visualizing stratigraphic plots

StratPercentages(arrays[, bbox, …])

A StratGroup for percentages plots

Functions

stratplot(df[, group_func, formatoptions, …])

Visualize a dataframe as a stratigraphic plot

class psy_strat.stratplot.StackedGroup(arrays, bbox=None, use_weakref=True, group=None)[source]

Bases: psy_strat.stratplot.StratAllInOne

A grouper for stacked plots

Parameters
  • arrays (list of xarray.DataArray) – The data arrays that are plotted by this StratGroup instance

  • bbox (matplotlib.transforms.Bbox) – The bounding box for the axes

  • use_weakref (bool) – If True, only weak references are used

  • group (str) – The groupname of this grouper. If not given, it will be taken from the 'maingroup' attribute of the first array

Attributes

bar_default_fmt

dict() -> new empty dictionary

default_fmt

dict() -> new empty dictionary

bar_default_fmt = {'categorical': False, 'legend': True, 'plot': 'stacked', 'title': '%(group)s', 'titleprops': {}, 'ytickprops': {'labelleft': False, 'left': False}}
default_fmt = {'legend': True, 'plot': 'stacked', 'title': '%(group)s', 'titleprops': {}, 'ytickprops': {'labelleft': False, 'left': False}}
class psy_strat.stratplot.StratAllInOne(arrays, bbox=None, use_weakref=True, group=None)[source]

Bases: psy_strat.stratplot.StratGroup

A StratGroup for single plots

Parameters
  • arrays (list of xarray.DataArray) – The data arrays that are plotted by this StratGroup instance

  • bbox (matplotlib.transforms.Bbox) – The bounding box for the axes

  • use_weakref (bool) – If True, only weak references are used

  • group (str) – The groupname of this grouper. If not given, it will be taken from the 'maingroup' attribute of the first array

Attributes

arrays

The arrays managed by this StratGroup.

bar_default_fmt

dict() -> new empty dictionary

default_fmt

dict() -> new empty dictionary

Methods

from_dataset(fig, bbox, ds, variables[, …])

Create StratGroup while creating a stratigraphic plot

group_plots(height)

Reimplemented to do nothing because all variables are in one axes

hide_array(name)

Hide the variable of the given name

is_visible(arr)

Check if the given arr is shown

reorder(names)

Reorder the plot objects

show_array(name)

Show the variable of the given name

property arrays

The arrays managed by this StratGroup. One array for each variable

bar_default_fmt = {'categorical': False, 'legend': True, 'title': '%(group)s', 'titleprops': {}, 'ytickprops': {'labelleft': False, 'left': False}}
default_fmt = {'legend': True, 'title': '%(group)s', 'titleprops': {}, 'ytickprops': {'labelleft': False, 'left': False}}
classmethod from_dataset(fig, bbox, ds, variables, fmt=None, project=None, ax0=None, use_bars=False, group=None)[source]

Create StratGroup while creating a stratigraphic plot

Create a stratigraphic plot within the given bbox of fig.

Parameters
Returns

The newly created instance with the arrays

Return type

StratGroup

group_plots(height)[source]

Reimplemented to do nothing because all variables are in one axes

hide_array(name)[source]

Hide the variable of the given name

Parameters

name (str) – The variable name

is_visible(arr)[source]

Check if the given arr is shown

reorder(names)[source]

Reorder the plot objects

Parameters

mapping (dict) – A mapping from the new index to the old one

show_array(name)[source]

Show the variable of the given name

Parameters

name (str) – The variable name

class psy_strat.stratplot.StratGroup(arrays, bbox=None, use_weakref=True, group=None)[source]

Bases: object

Base class for visualizing stratigraphic plots

Parameters
  • arrays (list of xarray.DataArray) – The data arrays that are plotted by this StratGroup instance

  • bbox (matplotlib.transforms.Bbox) – The bounding box for the axes

  • use_weakref (bool) – If True, only weak references are used

  • group (str) – The groupname of this grouper. If not given, it will be taken from the 'maingroup' attribute of the first array

Attributes

all_arrays

All variables of this group in the dataset

arr_names

arrays

The arrays managed by this StratGroup.

axes

bar_default_fmt

dict() -> new empty dictionary

default_fmt

The default formatoptions for the plots

figure

The figure that contains the plots

plotter_arrays

The data objects that contain the plotters

plotters

The plotters of the arrays

Methods

from_dataset(fig, bbox, ds, variables[, …])

Create StratGroup while creating a stratigraphic plot

group_plots([height])

Group the variables visually

hide_array(name)

Hide the variable of the given name

is_visible(arr)

Check if the given arr is shown

reorder(names)

Reorder the plot objects

resize_axes(axes)

Resize the axes in this group

show_array(name)

Show the variable of the given name

property all_arrays

All variables of this group in the dataset

property arr_names
property arrays

The arrays managed by this StratGroup. One array for each variable

property axes
bar_default_fmt = {'categorical': False, 'ytickprops': {'labelleft': False, 'left': False}}
default_fmt = {'ytickprops': {'labelleft': False, 'left': False}}

The default formatoptions for the plots

property figure

The figure that contains the plots

classmethod from_dataset(fig, bbox, ds, variables, fmt=None, project=None, ax0=None, use_bars=False, group=None)[source]

Create StratGroup while creating a stratigraphic plot

Create a stratigraphic plot within the given bbox of fig.

Parameters
Returns

The newly created instance with the arrays

Return type

StratGroup

group_plots(height=None)[source]

Group the variables visually

Parameters

height (float) – The height of the grouper. If not specified, the previous grouper_height attribute will be used

grouper_height = None
hide_array(name)[source]

Hide the variable of the given name

Parameters

name (str) – The variable name

is_visible(arr)[source]

Check if the given arr is shown

property plotter_arrays

The data objects that contain the plotters

property plotters

The plotters of the arrays

reorder(names)[source]

Reorder the plot objects

Parameters

names (list of str) – The variable names that should be the first

resize_axes(axes)[source]

Resize the axes in this group

show_array(name)[source]

Show the variable of the given name

Parameters

name (str) – The variable name

class psy_strat.stratplot.StratPercentages(arrays, bbox=None, use_weakref=True, group=None)[source]

Bases: psy_strat.stratplot.StratGroup

A StratGroup for percentages plots

Parameters
  • arrays (list of xarray.DataArray) – The data arrays that are plotted by this StratGroup instance

  • bbox (matplotlib.transforms.Bbox) – The bounding box for the axes

  • use_weakref (bool) – If True, only weak references are used

  • group (str) – The groupname of this grouper. If not given, it will be taken from the 'maingroup' attribute of the first array

Attributes

bar_default_fmt

dict() -> new empty dictionary

default_fmt

dict() -> new empty dictionary

Methods

resize_axes(axes)

Resize the axes in this group

bar_default_fmt = {'categorical': False, 'xlim': (0, 'rounded'), 'xticks': array([10, 30, 50, 70, 90]), 'ytickprops': {'labelleft': False, 'left': False}}
default_fmt = {'plot': 'areax', 'xlim': (0, 'rounded'), 'xticks': array([10, 30, 50, 70, 90]), 'ytickprops': {'labelleft': False, 'left': False}}
resize_axes(axes)[source]

Resize the axes in this group

psy_strat.stratplot.stratplot(df, group_func=None, formatoptions=None, ax=None, thresh=0.01, percentages=[], exclude=[], widths=None, calculate_percentages=True, min_percentage=20.0, trunc_height=0.3, fig=None, all_in_one=[], stacked=[], summed=[], use_bars=False, subgroups={})[source]

Visualize a dataframe as a stratigraphic plot

This functions takes a pandas.DataFrame and transforms it to a stratigraphic plot. The columns in the DataFrame may be grouped together using the group_func and the widths per group should then be specified. This function uses matplotlib axes for each subdiagram that all share a common vertical axes, the index of df. The variables are managed in the order of occurence in the input df but, however, are grouped together depending on the group_func.

The default is to plot every variable in df into separete line plots that line up vertically. You can use the percentages parameter for area plots, the all_in_one parameter for groups that should be all in one single plot (i.e. axes) and the stacked parameter for stacked plots.

Parameters
  • df (pandas.DataFrame) – The dataframe containing the data to plot.

  • group_func (function) –

    A function that groups the columns in the input df together. It must accept the name of a column and return the corresponding group name:

    def group_func(col_name: str):
        return "name of it's group"
    

    If this parameter is not specified, each column will be assigned to the ‘nogroup’ group that can then be used in the other parameters, such as formatoptions and percentages. Each group may also be divided into subgroups (see below), in this case, the group_func should return the corresponding subgroup.

  • formatoptions (dict) – The formatoption for each group. Depending on the chosen plot method, this contains the formatoptions for the psyplot plotter.

  • ax (matplotlib.axes.Axes) – The matplotlib axes to plot on. New axes will be created that cover all the space of the given axes. If this parameter is not specified and fig is None, a new matplotlib figure is created with a new matplotlib axes.

  • thresh (float) – A minimum number between 0 and 100 (by default 1%) that a percentages column has to fullfil in order to be included in the plot. If a variable is always below this threshold, it will not be included in the figure

  • percentages (list of str or bool) – The group names (see group_func) that represent percentage values. This variables will be visualized using an area plot and can be rescaled to sum up to 100% using the calculate_percentages parameter. This parameter can also be set to True if all groups shall be considered as percentage data

  • exclude (list of str) – Either group names of column names in df that should be excluded in the plot

  • widths (dict) –

    A mapping from group name to it’s relative width in the plot. The values of this mapping should some up to 1, e.g.:

    widths = {'group1': 0.3, 'group2': 0.5, 'group3': 0.2}
    

  • calculate_percentages (bool or list of str) – If True, rescale the groups mentioned in the percentages parameter to sum up to 100%. In case of a list of str, this parameter represents the group (or variable) names that shall be used for the normalization

  • min_percentage (float) – The minimum percentage (between 0 and 100) that should be covered by variables displaying percentages data. Each plot in one of the percentages groups will have at least have a xlim from 0 to min_percentage

  • trunc_height (float) – A float between 0 and 1. The fraction of the ax that should be reserved for the group titles.

  • fig (matplotlib.Figure) – The matplotlib figure to draw the plot on. If neither ax nor fig is specified, a new figure will be created.

  • all_in_one (list of str) – The groups mentioned in this parameter will all be plotted in one single axes whereas the default is to plot each variable in a separate plot

  • stacked (list of str) – The groups mentioned in this parameter will all be plotted in one single axes, stacked onto each other

  • summed (list of str) – The groups (or subgroups) mentioned in this parameter will be summed and an extra plot will be appended to the right of the stratigraphic diagram

  • use_bars (list of str or bool) – The variables specified in this parameter (or all variables if use_bars is True) will be visualized by a bar diagram, instead of a line or area plot.

  • subgroups (dict) –

    A mapping from group name to a list of subgroups, e.g.:

    subgroups = {'Pollen': ['Trees', 'Shrubs']}
    

    to divide an overarching group into subgroups.

Returns

  • psyplot.project.Project – The newly created psyplot subproject that contains the displayed data

  • list of StratGroup – The groupers that manage the different variables. There is one grouper per group