MCPcopy Index your code
hub / github.com/matplotlib/matplotlib / _check_gridspec_exists

Method _check_gridspec_exists

lib/matplotlib/gridspec.py:193–211  ·  view source on GitHub ↗

Check if the figure already has a gridspec with these dimensions, or create a new one

(figure, nrows, ncols)

Source from the content-addressed store, hash-verified

191
192 @staticmethod
193 def _check_gridspec_exists(figure, nrows, ncols):
194 """
195 Check if the figure already has a gridspec with these dimensions,
196 or create a new one
197 """
198 for ax in figure.get_axes():
199 gs = ax.get_gridspec()
200 if gs is not None:
201 if hasattr(gs, 'get_topmost_subplotspec'):
202 # This is needed for colorbar gridspec layouts.
203 # This is probably OK because this whole logic tree
204 # is for when the user is doing simple things with the
205 # add_subplot command. For complicated layouts
206 # like subgridspecs the proper gridspec is passed in...
207 gs = gs.get_topmost_subplotspec().get_gridspec()
208 if gs.get_geometry() == (nrows, ncols):
209 return gs
210 # else gridspec not found:
211 return GridSpec(nrows, ncols, figure=figure)
212
213 def __getitem__(self, key):
214 """Create and return a `.SubplotSpec` instance."""

Callers 2

_from_subplot_argsMethod · 0.80
subplot2gridFunction · 0.80

Calls 4

GridSpecClass · 0.85
get_gridspecMethod · 0.45
get_geometryMethod · 0.45

Tested by

no test coverage detected