Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Replace "panels" with EdgeStack, permit working directly with add_subplot/GridSpec #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 13 additions & 21 deletions proplot/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,13 @@ def _parse_format(mode=2, rc_kw=None, **kwargs):
class Axes(maxes.Axes):
"""Lowest-level axes subclass. Handles titles and axis
sharing. Adds several new methods and overrides existing ones."""
def __init__(self, *args, number=None, main=False, **kwargs):
def __init__(self, *args, number=None, **kwargs):
"""
Parameters
----------
number : int
The subplot number, used for a-b-c labeling. See `~Axes.format`
for details. Note the first axes is ``1``, not ``0``.
main : bool, optional
Used internally, indicates whether this is a "main axes" rather
than a twin, panel, or inset axes.
*args, **kwargs
Passed to `~matplotlib.axes.Axes`.

Expand Down Expand Up @@ -166,8 +163,6 @@ def __init__(self, *args, number=None, main=False, **kwargs):
self._alty_parent = None
self._altx_parent = None
self.number = number # for abc numbering
if main:
self.figure._axes_main.append(self)

# On-the-fly legends and colorbars
self._auto_colorbar = {}
Expand Down Expand Up @@ -357,10 +352,10 @@ def _range_gridspec(self, x):
raise RuntimeError(f'Axes is not a subplot.')
ss = self.get_subplotspec()
if x == 'x':
_, _, _, _, col1, col2 = ss.get_active_rows_columns()
_, _, _, _, col1, col2 = ss.get_rows_columns()
return col1, col2
else:
_, _, row1, row2, _, _ = ss.get_active_rows_columns()
_, _, row1, row2, _, _ = ss.get_rows_columns()
return row1, row2

def _range_tightbbox(self, x):
Expand All @@ -383,6 +378,7 @@ def _reassign_suplabel(self, side):
# Place column and row labels on panels instead of axes -- works when
# this is called on the main axes *or* on the relevant panel itself
# TODO: Mixed figure panels with super labels? How does that work?
# TODO: Remove this when panels implemented as stacks!
if side == self._panel_side:
ax = self._panel_parent
else:
Expand Down Expand Up @@ -413,6 +409,7 @@ def _reassign_title(self):
# called on the main axes *or* on the top panel itself. This is
# critical for bounding box calcs; not always clear whether draw() and
# get_tightbbox() are called on the main axes or panel first
# TODO: Remove this when panels implemented as stacks!
if self._panel_side == 'top' and self._panel_parent:
ax = self._panel_parent
else:
Expand Down Expand Up @@ -960,7 +957,6 @@ def colorbar(
For outer colorbars only. The space between the colorbar and the
main axes. Units are interpreted by `~proplot.utils.units`.
When :rcraw:`tight` is ``True``, this is adjusted automatically.
Otherwise, the default is :rc:`subplots.panelpad`.
frame, frameon : bool, optional
For inset colorbars, indicates whether to draw a "frame", just
like `~matplotlib.axes.Axes.legend`. Default is
Expand Down Expand Up @@ -996,8 +992,9 @@ def colorbar(
self.patch.set_alpha(0)
self._panel_filled = True

# Draw colorbar with arbitrary length relative to full length
# of panel
# Draw colorbar with arbitrary length relative to full panel length
# TODO: Can completely remove references to GridSpecFromSubplotSpec
# if implement colorbars as "parasite" objects instead.
side = self._panel_side
length = _notNone(length, rc['colorbar.length'])
subplotspec = self.get_subplotspec()
Expand All @@ -1020,10 +1017,9 @@ def colorbar(
height_ratios=((1 - length) / 2, length, (1 - length) / 2),
)
subplotspec = gridspec[1]
with self.figure._authorize_add_subplot():
ax = self.figure.add_subplot(subplotspec, projection=None)
if ax is self:
raise ValueError # should never happen
ax = self.figure.add_subplot(
subplotspec, main=False, projection=None
)
self.add_child_axes(ax)

# Location
Expand Down Expand Up @@ -1197,7 +1193,6 @@ def legend(self, *args, loc=None, width=None, space=None, **kwargs):
For outer legends only. The space between the axes and the legend
box. Units are interpreted by `~proplot.utils.units`.
When :rcraw:`tight` is ``True``, this is adjusted automatically.
Otherwise, the default is :rc:`subplots.panelpad`.

Other parameters
----------------
Expand Down Expand Up @@ -1426,7 +1421,6 @@ def panel_axes(self, side, **kwargs):
space : float or str or list thereof, optional
Empty space between the main subplot and the panel.
When :rcraw:`tight` is ``True``, this is adjusted automatically.
Otherwise, the default is :rc:`subplots.panelpad`.
share : bool, optional
Whether to enable axis sharing between the *x* and *y* axes of the
main subplot and the panel long axes for each panel in the stack.
Expand Down Expand Up @@ -2691,8 +2685,7 @@ def altx(self, **kwargs):
# See https://github.com/matplotlib/matplotlib/blob/master/lib/matplotlib/axes/_subplots.py # noqa
if self._altx_child or self._altx_parent:
raise RuntimeError('No more than *two* twin axes are allowed.')
with self.figure._authorize_add_subplot():
ax = self._make_twin_axes(sharey=self, projection='xy')
ax = self._make_twin_axes(sharey=self, projection='xy')
ax.set_autoscaley_on(self.get_autoscaley_on())
ax.grid(False)
self._altx_child = ax
Expand All @@ -2708,8 +2701,7 @@ def alty(self, **kwargs):
"""This docstring is replaced below."""
if self._alty_child or self._alty_parent:
raise RuntimeError('No more than *two* twin axes are allowed.')
with self.figure._authorize_add_subplot():
ax = self._make_twin_axes(sharex=self, projection='xy')
ax = self._make_twin_axes(sharex=self, projection='xy')
ax.set_autoscalex_on(self.get_autoscalex_on())
ax.grid(False)
self._alty_child = ax
Expand Down
Loading