Skip to content

Commit

Permalink
ADD: plot.subplots()
Browse files Browse the repository at this point in the history
  • Loading branch information
christianbrodbeck committed May 10, 2021
1 parent 848d653 commit a71bf47
Show file tree
Hide file tree
Showing 2 changed files with 62 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
61 changes: 61 additions & 0 deletions eelbrain/plot/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2667,6 +2667,67 @@ 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,
bottom: float = None,
top: float = None,
hspace: 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.
bottom
Margin below the axes.
top
Margin above the axes.
hspace
Height of the margin between axes.
**
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.w,
'bottom': layout.margins['bottom'] / layout.h,
'top': 1 - layout.margins['top'] / layout.h,
'hspace': layout.margins['hspace'] / layout.h,
}
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 a71bf47

Please sign in to comment.