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

Skip to content

Permit using add_subplot directly #48

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 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5b09d89
Try to pop vmin and vmax out of norm_kw
lukelbd Sep 2, 2019
a3ebbb1
Respect vmin and vmax as hard minimum/maximum
lukelbd Sep 2, 2019
ba2ce6f
Merge branch 'master' into panels-change-gridspec
lukelbd Sep 2, 2019
bad8024
Remove PanelAxes, and remove 'panels' args from subplots()! Colorbar …
lukelbd Sep 3, 2019
aa4cccf
On-the-fly figure colorbars and legends!
lukelbd Sep 3, 2019
c264999
Return axes_grid of panels, fix _panels_kwargs bug
lukelbd Sep 3, 2019
088a537
Fix axes_grid docstring
lukelbd Sep 3, 2019
bf87d3a
Minor
lukelbd Sep 3, 2019
cfe7e66
axes_grid docstring
lukelbd Sep 3, 2019
3205230
Zoom attribute change
lukelbd Sep 3, 2019
00bd9ff
Auto legend cleanup
lukelbd Sep 3, 2019
25934db
Comments
lukelbd Sep 3, 2019
73dd02c
Better 'span' fig panel aliases
lukelbd Sep 3, 2019
9254346
Add AAAS to journals; fix bug in pulling their dims
bradyrx Sep 4, 2019
32c4cc8
Move journal dictionary to top; add testing for journals
bradyrx Sep 4, 2019
7b6e4e0
Misc bugfixes and cleanup
lukelbd Sep 5, 2019
b8df9e1
Panels bugfix
lukelbd Sep 5, 2019
c67c3f8
Remove print statement
lukelbd Sep 5, 2019
5643867
Update documentation to reflect new colorbars, legends usage, add ins…
lukelbd Sep 5, 2019
4a43155
Merge pull request #31 from lukelbd/panels-change-gridspec
lukelbd Sep 5, 2019
acc905c
Remove duplicate 'Plotting wrappers' docs
lukelbd Sep 5, 2019
c2ae600
All caps constants
lukelbd Sep 6, 2019
f9c6eda
Name change fix
lukelbd Sep 6, 2019
c880ef1
Figure documentation
lukelbd Sep 6, 2019
7a611b5
_subplots_geometry cleanup
lukelbd Sep 6, 2019
43943a7
Merge pull request #30 from bradyrx/add_aaas_journals
lukelbd Sep 6, 2019
ddcc5fe
Repair dead links in wrappers.py
lukelbd Sep 6, 2019
bb3f21a
Merge branch 'master' of https://github.com/lukelbd/proplot
lukelbd Sep 6, 2019
039aea3
Demo stacked figure panels
lukelbd Sep 6, 2019
8804efc
_reassign_title bugfix, minor docs changes
lukelbd Sep 9, 2019
2b78889
Preliminary add_subplot changes
lukelbd Sep 9, 2019
695318b
Merge from master
lukelbd Sep 14, 2019
513d3e0
Fix import error
lukelbd Sep 14, 2019
ff760aa
Merge and fix docs conflicts
lukelbd Sep 18, 2019
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
28,153 changes: 9,397 additions & 18,756 deletions docs/colors/colors_10_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,466 changes: 2,414 additions & 52 deletions docs/colors/colors_36_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,002 changes: 2,002 additions & 0 deletions docs/colors/tutorial_105_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13,745 changes: 13,745 additions & 0 deletions docs/colors/tutorial_112_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5,513 changes: 5,513 additions & 0 deletions docs/colors/tutorial_114_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19,026 changes: 19,026 additions & 0 deletions docs/colors/tutorial_114_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25,854 changes: 25,854 additions & 0 deletions docs/colors/tutorial_119_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10,126 changes: 10,126 additions & 0 deletions docs/colors/tutorial_119_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6,283 changes: 6,283 additions & 0 deletions docs/colors/tutorial_126_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3,536 changes: 3,536 additions & 0 deletions docs/colors/tutorial_131_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1,548 changes: 1,548 additions & 0 deletions docs/colors/tutorial_133_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3,013 changes: 3,013 additions & 0 deletions docs/colors/tutorial_138_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9,190 changes: 9,190 additions & 0 deletions docs/colors/tutorial_138_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3,401 changes: 3,401 additions & 0 deletions docs/colors/tutorial_157_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2,322 changes: 2,322 additions & 0 deletions docs/colors/tutorial_157_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4,676 changes: 4,676 additions & 0 deletions docs/colors/tutorial_160_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3,418 changes: 3,418 additions & 0 deletions docs/colors/tutorial_163_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3,677 changes: 3,677 additions & 0 deletions docs/colors/tutorial_166_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7,964 changes: 7,964 additions & 0 deletions docs/colors/tutorial_169_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3,988 changes: 3,988 additions & 0 deletions docs/colors/tutorial_172_1.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5,189 changes: 5,189 additions & 0 deletions docs/colors/tutorial_175_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4,613 changes: 4,613 additions & 0 deletions docs/colors/tutorial_96_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7,891 changes: 7,256 additions & 635 deletions docs/plots/plots_11_0.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
92 changes: 80 additions & 12 deletions proplot/subplots.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#!/usr/bin/env python3
"""
The starting point for creating custom ProPlot figures and axes.
The `subplots` function is all you'll need to directly use here.
It returns a `Figure` instance and an `axes_grid` container of
`~proplot.axes.Axes` axes, whose positions are controlled by the
`FlexibleGridSpec` class.
The `subplots` function is your starting point for creating custom
ProPlot figures and axes. It returns a `Figure` instance and an
`axes_grid` container of `~proplot.axes.Axes` axes, whose positions are
controlled by the `FlexibleGridSpec` class.

.. raw:: html

Expand Down Expand Up @@ -74,6 +73,7 @@
import matplotlib.figure as mfigure
import matplotlib.transforms as mtransforms
import matplotlib.gridspec as mgridspec
from numbers import Integral
try:
import matplotlib.backends.backend_macosx as mbackend
except ImportError:
Expand Down Expand Up @@ -1457,12 +1457,78 @@ def _update_suptitle(self, title, **kwargs):
if kwargs:
self._suptitle.update(kwargs)

def add_subplot(self, *args, **kwargs):
"""Issues warning for new users that try to call
`~matplotlib.figure.Figure.add_subplot` manually."""
if self._locked:
warnings.warn('Using "fig.add_subplot()" with ProPlot figures may result in unexpected behavior. Please use "proplot.subplots()" instead.')
ax = super().add_subplot(*args, **kwargs)
def add_subplot(self, *args,
proj=None, projection=None, basemap=False,
**kwargs):
"""
Adds subplot using the existing figure gridspec.

Parameters
----------
*args
If `~matplotlib.gridspec.SubplotSpec` instance, must be a child
of the main subplot gridspec!

If a 3-digit integer or a tuple indicating (nrows, ncols, index),
the geometry must match the geometry of the input gridspec!
proj, projection : str, optional
The registered matplotlib projection name, or a basemap or cartopy
map projection name. For valid map projection names, see the
:ref:`Table of projections`.
"""
# TODO: Consider permitting add_subplot?
# Copied from matplotlib add_subplot
if not len(args):
args = (1, 1, 1)
if len(args) == 1 and isinstance(args[0], Integral):
if not 100 <= args[0] <= 999:
raise ValueError(f'Integer subplot specification must be a three-digit number, not {args[0]!r}.')
args = tuple(map(int, str(args[0])))
# Copied from SubplotBase __init__ and modified to enforce restrictions
gridspec = self._gridspec_main
subplotspec = None
if len(args) == 1:
if isinstance(args[0], mgridspec.SubplotSpec):
subplotspec = args[0]
else:
try:
s = str(int(args[0]))
rows, cols, num = map(int, s)
except ValueError:
raise ValueError(f'Single argument to subplot must be a 3-digit integer, not {args[0]!r}.')
elif len(args) == 3:
rows, cols, num = args
else:
raise ValueError(f'Illegal argument(s) to add_subplot: {args}')
if subplotspec is None:
rows = int(rows)
cols = int(cols)
if isinstance(num, tuple) and len(num) == 2:
num = [int(n) for n in num]
else:
if num < 1 or num > rows*cols:
raise ValueError(f'num must be 1 <= num <= {rows*cols}, not {num}')
if (rows, cols) != gridspec.get_active_geometry():
raise ValueError(f'Input arguments {args!r} conflict with existing gridspec geometry of {rows} rows, {cols} columns.')
if not isinstance(num, tuple):
num = (num, num)
subplotspec = gridspec[(num[0] - 1):num[1]]

# The default is CartesianAxes
proj = _notNone(proj, projection, 'cartesian', names=('proj','projection'))
# Builtin matplotlib polar axes, just use my overridden version
if proj == 'polar':
proj = 'polar2'
# Custom Basemap and Cartopy axes
# TODO: Have Proj return all unused keyword args, with a
# map_projection = obj entry, and maybe hide the Proj constructor as
# an argument processing utility?
elif proj != 'cartesian':
kwargs = projs.Proj(proj, basemap=basemap, **kwargs)
proj = 'basemap' if basemap else 'cartopy'

# Initialize
ax = super().add_subplot(subplotspec, projection=proj, **kwargs)
return ax

def colorbar(self, *args,
Expand Down Expand Up @@ -1844,7 +1910,9 @@ def subplots(array=None, ncols=1, nrows=1,
for the *x* axis, *y* axis, or both axes. Only has an effect when
`spanx`, `spany`, or `span` are ``False``.
proj, projection : str or dict-like, optional
The map projection name. The argument is interpreted as follows.
The registered matplotlib projection name, or a basemap or cartopy
map projection name. For valid map projection names, see the
:ref:`Table of projections`. Argument is interpreted as follows.

* If string, this projection is used for all subplots. For valid
names, see the :ref:`Table of projections`.
Expand Down