|
13 | 13 | import matplotlib.figure as mfigure |
14 | 14 | import matplotlib.transforms as mtransforms |
15 | 15 | import matplotlib.gridspec as mgridspec |
| 16 | +from numbers import Integral |
16 | 17 | from .rctools import rc |
17 | 18 | from .utils import _warn_proplot, _notNone, _counter, _setstate, units |
18 | 19 | from . import projs, axes |
@@ -1642,16 +1643,57 @@ def colorbar( |
1642 | 1643 | *args, **kwargs |
1643 | 1644 | Passed to `~proplot.axes.Axes.colorbar`. |
1644 | 1645 | """ |
1645 | | - if 'cax' in kwargs: |
1646 | | - return super().colorbar(*args, **kwargs) |
1647 | | - elif 'ax' in kwargs: |
1648 | | - return kwargs.pop('ax').colorbar( |
1649 | | - *args, space=space, width=width, **kwargs) |
1650 | | - else: |
1651 | | - ax = self._add_figure_panel( |
1652 | | - loc, space=space, width=width, span=span, |
1653 | | - row=row, col=col, rows=rows, cols=cols) |
1654 | | - return ax.colorbar(*args, loc='_fill', **kwargs) |
| 1646 | + ax = kwargs.pop('ax', None) |
| 1647 | + cax = kwargs.pop('cax', None) |
| 1648 | + # Fill this axes |
| 1649 | + if cax is not None: |
| 1650 | + return super().colorbar(*args, cax=cax, **kwargs) |
| 1651 | + # Generate axes panel |
| 1652 | + elif ax is not None: |
| 1653 | + return ax.colorbar(*args, space=space, width=width, **kwargs) |
| 1654 | + # Generate figure panel |
| 1655 | + ax = self._add_figure_panel( |
| 1656 | + loc, space=space, width=width, span=span, |
| 1657 | + row=row, col=col, rows=rows, cols=cols |
| 1658 | + ) |
| 1659 | + return ax.colorbar(*args, loc='_fill', **kwargs) |
| 1660 | + |
| 1661 | + def get_alignx(self): |
| 1662 | + """Return the *x* axis label alignment mode.""" |
| 1663 | + return self._alignx |
| 1664 | + |
| 1665 | + def get_aligny(self): |
| 1666 | + """Return the *y* axis label alignment mode.""" |
| 1667 | + return self._aligny |
| 1668 | + |
| 1669 | + def get_gridspec(self): |
| 1670 | + """Return the single `GridSpec` instance associated with this figure. |
| 1671 | + If the `GridSpec` has not yet been initialized, returns ``None``.""" |
| 1672 | + return self._gridspec |
| 1673 | + |
| 1674 | + def get_ref_axes(self): |
| 1675 | + """Return the reference axes associated with the reference axes |
| 1676 | + number `Figure.ref`.""" |
| 1677 | + for ax in self._mainaxes: |
| 1678 | + if ax.number == self.ref: |
| 1679 | + return ax |
| 1680 | + return None # no error |
| 1681 | + |
| 1682 | + def get_sharex(self): |
| 1683 | + """Return the *x* axis sharing level.""" |
| 1684 | + return self._sharex |
| 1685 | + |
| 1686 | + def get_sharey(self): |
| 1687 | + """Return the *y* axis sharing level.""" |
| 1688 | + return self._sharey |
| 1689 | + |
| 1690 | + def get_spanx(self): |
| 1691 | + """Return the *x* axis label spanning mode.""" |
| 1692 | + return self._spanx |
| 1693 | + |
| 1694 | + def get_spany(self): |
| 1695 | + """Return the *y* axis label spanning mode.""" |
| 1696 | + return self._spany |
1655 | 1697 |
|
1656 | 1698 | def draw(self, renderer): |
1657 | 1699 | # Certain backends *still* have issues with the tight layout |
@@ -1715,16 +1757,16 @@ def legend( |
1715 | 1757 | *args, **kwargs |
1716 | 1758 | Passed to `~proplot.axes.Axes.legend`. |
1717 | 1759 | """ |
1718 | | - if 'ax' in kwargs: |
1719 | | - return kwargs.pop('ax').legend( |
1720 | | - *args, space=space, width=width, **kwargs |
1721 | | - ) |
1722 | | - else: |
1723 | | - ax = self._add_figure_panel( |
1724 | | - loc, space=space, width=width, span=span, |
1725 | | - row=row, col=col, rows=rows, cols=cols |
1726 | | - ) |
1727 | | - return ax.legend(*args, loc='_fill', **kwargs) |
| 1760 | + ax = kwargs.pop('ax', None) |
| 1761 | + # Generate axes panel |
| 1762 | + if ax is not None: |
| 1763 | + return ax.legend(*args, space=space, width=width, **kwargs) |
| 1764 | + # Generate figure panel |
| 1765 | + ax = self._add_figure_panel( |
| 1766 | + loc, space=space, width=width, span=span, |
| 1767 | + row=row, col=col, rows=rows, cols=cols |
| 1768 | + ) |
| 1769 | + return ax.legend(*args, loc='_fill', **kwargs) |
1728 | 1770 |
|
1729 | 1771 | def save(self, filename, **kwargs): |
1730 | 1772 | # Alias for `~Figure.savefig` because ``fig.savefig`` is redundant. |
@@ -1753,6 +1795,75 @@ def set_canvas(self, canvas): |
1753 | 1795 | canvas.print_figure = _canvas_preprocess(canvas, 'print_figure') |
1754 | 1796 | super().set_canvas(canvas) |
1755 | 1797 |
|
| 1798 | + def set_alignx(self, value): |
| 1799 | + """Set the *x* axis label alignment mode.""" |
| 1800 | + self.stale = True |
| 1801 | + self._alignx = bool(value) |
| 1802 | + |
| 1803 | + def set_aligny(self, value): |
| 1804 | + """Set the *y* axis label alignment mode.""" |
| 1805 | + self.stale = True |
| 1806 | + self._aligny = bool(value) |
| 1807 | + |
| 1808 | + def set_sharex(self, value): |
| 1809 | + """Set the *x* axis sharing level.""" |
| 1810 | + value = int(value) |
| 1811 | + if value not in range(4): |
| 1812 | + raise ValueError( |
| 1813 | + 'Invalid sharing level sharex={value!r}. ' |
| 1814 | + 'Axis sharing level can be 0 (share nothing), ' |
| 1815 | + '1 (hide axis labels), ' |
| 1816 | + '2 (share limits and hide axis labels), or ' |
| 1817 | + '3 (share limits and hide axis and tick labels).' |
| 1818 | + ) |
| 1819 | + self.stale = True |
| 1820 | + self._sharex = value |
| 1821 | + |
| 1822 | + def set_sharey(self, value): |
| 1823 | + """Set the *y* axis sharing level.""" |
| 1824 | + value = int(value) |
| 1825 | + if value not in range(4): |
| 1826 | + raise ValueError( |
| 1827 | + 'Invalid sharing level sharey={value!r}. ' |
| 1828 | + 'Axis sharing level can be 0 (share nothing), ' |
| 1829 | + '1 (hide axis labels), ' |
| 1830 | + '2 (share limits and hide axis labels), or ' |
| 1831 | + '3 (share limits and hide axis and tick labels).' |
| 1832 | + ) |
| 1833 | + self.stale = True |
| 1834 | + self._sharey = value |
| 1835 | + |
| 1836 | + def set_spanx(self, value): |
| 1837 | + """Set the *x* axis label spanning mode.""" |
| 1838 | + self.stale = True |
| 1839 | + self._spanx = bool(value) |
| 1840 | + |
| 1841 | + def set_spany(self, value): |
| 1842 | + """Set the *y* axis label spanning mode.""" |
| 1843 | + self.stale = True |
| 1844 | + self._spany = bool(value) |
| 1845 | + |
| 1846 | + @property |
| 1847 | + def gridspec(self): |
| 1848 | + """The single `GridSpec` instance used for all subplots |
| 1849 | + in the figure.""" |
| 1850 | + return self._gridspec_main |
| 1851 | + |
| 1852 | + @property |
| 1853 | + def ref(self): |
| 1854 | + """The reference axes number. The `axwidth`, `axheight`, and `aspect` |
| 1855 | + `subplots` and `figure` arguments are applied to this axes, and aspect |
| 1856 | + ratio is conserved for this axes in tight layout adjustment.""" |
| 1857 | + return self._ref |
| 1858 | + |
| 1859 | + @ref.setter |
| 1860 | + def ref(self, ref): |
| 1861 | + if not isinstance(ref, Integral) or ref < 1: |
| 1862 | + raise ValueError( |
| 1863 | + f'Invalid axes number {ref!r}. Must be integer >=1.') |
| 1864 | + self.stale = True |
| 1865 | + self._ref = ref |
| 1866 | + |
1756 | 1867 | def set_size_inches(self, w, h=None, forward=True, auto=False): |
1757 | 1868 | # Set the figure size and, if this is being called manually or from |
1758 | 1869 | # an interactive backend, override the geometry tracker so users can |
|
0 commit comments