Skip to content

Commit

Permalink
ADD: plot.subplots()
Browse files Browse the repository at this point in the history
  • Loading branch information
christianbrodbeck committed Jun 16, 2021
1 parent 181dcee commit 0b14163
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 1 deletion.
2 changes: 1 addition & 1 deletion eelbrain/plot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from .._colorspaces import two_step_colormap

from ._base import reset_rc
from ._base import reset_rc, subplots
from ._colors import ColorBar, ColorGrid, ColorList
from ._decorations import figure_outline, mark_difference
from ._figure import Figure
Expand Down
69 changes: 69 additions & 0 deletions eelbrain/plot/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2667,6 +2667,75 @@ def _configure_axes(self, axes):
ax.id = i


def subplots(
nrows: int = 1,
ncols: int = 1,
axh: float = None,
axw: float = None,
h: float = None,
w: float = None,
left: float = None,
right: float = None,
wspace: float = None,
width_ratios: Sequence[float] = None,
bottom: float = None,
top: float = None,
hspace: float = None,
height_ratios: Sequence[float] = None,
**kwargs,
):
"""Specify :func:`matplotlib.pyplot.subplots` parameters in inches
Parameters
----------
nrows
Number of subplot rows.
ncols
Number of subplot columns.
axh
Height of each axes.
axw
Width of each axes.
h
Figure height.
w
Figure width.
left
Margin to the left of the axes.
right
Margin to the right of the axes.
wspace
Width of the margin between axes.
width_ratios
The relative widths of the columns (see :class:`matplotlib.gridspec.GridSpec`).
bottom
Margin below the axes.
top
Margin above the axes.
hspace
Height of the margin between axes.
height_ratios
The relative heights of the rows (see :class:`matplotlib.gridspec.GridSpec`).
**
Other parameters for :func:`matplotlib.pyplot.subplots`.
"""
from matplotlib import pyplot

margins = {'left': left, 'bottom': bottom, 'right': right, 'top': top, 'wspace': wspace, 'hspace': hspace}
layout = Layout(nrows*ncols, 1, 2, False, None, h, w, axh, axw, nrows, ncols, None, margins)
gridspec_kw = {
'left': layout.margins['left'] / layout.w,
'right': 1 - layout.margins['right'] / layout.w,
'wspace': layout.margins['wspace'] / layout.axw,
'width_ratios': width_ratios,
'bottom': layout.margins['bottom'] / layout.h,
'top': 1 - layout.margins['top'] / layout.h,
'hspace': layout.margins['hspace'] / layout.axh,
'height_ratios': height_ratios,
}
return pyplot.subplots(layout.nrow, layout.ncol, figsize=(layout.w, layout.h), gridspec_kw=gridspec_kw, **kwargs)


class ColorBarMixin:
"""Colorbar toolbar button mixin
Expand Down

0 comments on commit 0b14163

Please sign in to comment.