Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _spaces_as_ratios(self,
hspace=None, wspace=None, # spacing between axes
height_ratios=None, width_ratios=None,
**kwargs):
"""For keyword arg usage, see `FlexibleGridSpecBase`."""
# Parse flexible input
nrows = self._nrows_visible
ncols = self._ncols_visible
hratios = np.atleast_1d(_default(height_ratios, 1))
wratios = np.atleast_1d(_default(width_ratios, 1))
hspace = np.atleast_1d(_default(hspace, np.mean(hratios)*0.10)) # this is relative to axes
wspace = np.atleast_1d(_default(wspace, np.mean(wratios)*0.10))
if len(wspace)==1:
wspace = np.repeat(wspace, (ncols-1,)) # note: may be length 0
if len(hspace)==1:
hspace = np.repeat(hspace, (nrows-1,))
if len(wratios)==1:
wratios = np.repeat(wratios, (ncols,))
if len(hratios)==1:
hratios = np.repeat(hratios, (nrows,))
# Verify input ratios and spacings
# Translate height/width spacings, implement as extra columns/rows
if len(hratios) != nrows:
raise ValueError(f'Got {nrows} rows, but {len(hratios)} hratios.')
if len(wratios) != ncols:
raise ValueError(f'Got {ncols} columns, but {len(wratios)} wratios.')
if ncols>1 and len(wspace) != ncols-1:
axwidth = units(axwidth)
axheight = units(axheight)
# Gridspec defaults
# NOTE: Ratios are scaled to take physical units in _subplots_kwargs, so
# user can manually provide hspace and wspace in physical units.
hspace = np.atleast_1d(units(_default(hspace,
rc['subplot.titlespace'] + rc['subplot.innerspace'] if sharex==3
else rc['subplot.xlabspace'] if sharex in (1,2) # space for tick labels and title
else rc['subplot.titlespace'] + rc['subplot.xlabspace'])))
wspace = np.atleast_1d(units(_default(wspace,
rc['subplot.innerspace'] if sharey==3
else rc['subplot.ylabspace'] - rc['subplot.titlespace'] if sharey in (1,2) # space for tick labels only
else rc['subplot.ylabspace']
)))
wratios = np.atleast_1d(_default(width_ratios, wratios, axwidths, 1))
hratios = np.atleast_1d(_default(height_ratios, hratios, axheights, 1))
if len(wspace)==1:
wspace = np.repeat(wspace, (ncols-1,))
if len(hspace)==1:
hspace = np.repeat(hspace, (nrows-1,))
if flush or wflush:
wspace = wspace*0.0
if flush or hflush:
hspace = hspace*0.0
if len(wratios)==1:
wratios = np.repeat(wratios, (ncols,))
if len(hratios)==1:
hratios = np.repeat(hratios, (nrows,))
left = units(_default(left, rc['subplot.ylabspace']))
bottom = units(_default(bottom, rc['subplot.xlabspace']))
right = units(_default(right, rc['subplot.nolabspace']))
top = units(_default(top, rc['subplot.titlespace']))
xgridminor = _default(xgridminor, grid and axis in ('x','both') and which in ('minor','both'))
ygridminor = _default(ygridminor, grid and axis in ('y','both') and which in ('minor','both'))
# Weird bug override
# NOTE: Latest matplotlib versions seem to have fixed below bug. For
# now remove warning message, because it is triggered whenever user
# draws a top 'flush' panel.
# if xticklabelloc in ('both','top') and (xlabelloc!='top' or not xlabel): # xtickloc *cannot* be 'top', *only* appears for 'both'
# warnings.warn('This keyword combo causes matplotlib bug where title is not offset from tick labels. Try again with xticklabelloc="bottom" or xlabelloc="top". Defaulting to the latter.')
# xticklabelloc = xlabelloc = 'top'
# Sensible defaults for spine, tick, tick label, and label locations
# NOTE: Allow tick labels to be present without ticks! User may
# want this sometimes! Same goes for spines!
xspineloc = _default(xloc, xspineloc)
yspineloc = _default(yloc, yspineloc)
xtickloc = _default(xtickloc, xspineloc, _rcloc_to_stringloc('x', 'xtick'))
ytickloc = _default(ytickloc, yspineloc, _rcloc_to_stringloc('y', 'ytick'))
xspineloc = _default(xspineloc, _rcloc_to_stringloc('x', 'axes.spines'))
yspineloc = _default(yspineloc, _rcloc_to_stringloc('y', 'axes.spines'))
xticklabelloc = _default(xticklabelloc, xtickloc)
yticklabelloc = _default(yticklabelloc, ytickloc)
xlabelloc = _default(xlabelloc, xticklabelloc)
ylabelloc = _default(ylabelloc, yticklabelloc)
if xlabelloc not in (None,'bottom','top'): # e.g. 'both' or 'neither'
xlabelloc = 'bottom'
if ylabelloc not in (None,'left','right'):
ylabelloc = 'left'
# Begin loop
for (axis, label, color, ticklen, margin,
tickloc, spineloc, ticklabelloc, labelloc,
bounds, grid, gridminor, tickminor, tickminorlocator,
def _spaces_as_ratios(self,
hspace=None, wspace=None, # spacing between axes
height_ratios=None, width_ratios=None,
**kwargs):
"""For keyword arg usage, see `FlexibleGridSpecBase`."""
# Parse flexible input
nrows = self._nrows_visible
ncols = self._ncols_visible
hratios = np.atleast_1d(_default(height_ratios, 1))
wratios = np.atleast_1d(_default(width_ratios, 1))
hspace = np.atleast_1d(_default(hspace, np.mean(hratios)*0.10)) # this is relative to axes
wspace = np.atleast_1d(_default(wspace, np.mean(wratios)*0.10))
if len(wspace)==1:
wspace = np.repeat(wspace, (ncols-1,)) # note: may be length 0
if len(hspace)==1:
hspace = np.repeat(hspace, (nrows-1,))
if len(wratios)==1:
wratios = np.repeat(wratios, (ncols,))
if len(hratios)==1:
hratios = np.repeat(hratios, (nrows,))
# Verify input ratios and spacings
# Translate height/width spacings, implement as extra columns/rows
if len(hratios) != nrows:
raise ValueError(f'Got {nrows} rows, but {len(hratios)} hratios.')
if len(wratios) != ncols:
raise ValueError(f'Got {ncols} columns, but {len(wratios)} wratios.')
if ncols>1 and len(wspace) != ncols-1:
ytickminor = _default(ytickminor, rc['ytick.minor.visible'])
xformatter = _default(xticklabels, xformatter) # default is just matplotlib version
yformatter = _default(yticklabels, yformatter)
xlocator = _default(xticks, xlocator) # default is AutoLocator, no setting
ylocator = _default(yticks, ylocator)
xminorlocator = _default(xminorticks, xminorlocator) # default is AutoMinorLocator, no setting
yminorlocator = _default(yminorticks, yminorlocator)
# Grid defaults are more complicated
axis = rc.get('axes.grid.axis') # always need this property
grid, which = rc['axes.grid'], rc['axes.grid.which']
if which is not None or grid is not None: # only if *one* was changed recently!
if grid is None:
grid = rc.get('axes.grid')
elif which is None:
which = rc.get('axes.grid.which')
xgrid = _default(xgrid, grid and axis in ('x','both') and which in ('major','both'))
ygrid = _default(ygrid, grid and axis in ('y','both') and which in ('major','both'))
xgridminor = _default(xgridminor, grid and axis in ('x','both') and which in ('minor','both'))
ygridminor = _default(ygridminor, grid and axis in ('y','both') and which in ('minor','both'))
# Weird bug override
# NOTE: Latest matplotlib versions seem to have fixed below bug. For
# now remove warning message, because it is triggered whenever user
# draws a top 'flush' panel.
# if xticklabelloc in ('both','top') and (xlabelloc!='top' or not xlabel): # xtickloc *cannot* be 'top', *only* appears for 'both'
# warnings.warn('This keyword combo causes matplotlib bug where title is not offset from tick labels. Try again with xticklabelloc="bottom" or xlabelloc="top". Defaulting to the latter.')
# xticklabelloc = xlabelloc = 'top'
# Sensible defaults for spine, tick, tick label, and label locations
# NOTE: Allow tick labels to be present without ticks! User may
# want this sometimes! Same goes for spines!
xspineloc = _default(xloc, xspineloc)
yspineloc = _default(yloc, yspineloc)
nrows = array.shape[0]
ncols = array.shape[1]
#--------------------------------------------------------------------------#
# Panels
#--------------------------------------------------------------------------#
# Parse outer panel kwargs, consolidate settings
for ipanel in (panel,legend,colorbar):
for side in (ipanel or ''):
if side + 'array' in kwargs:
kwargs[side + 'span'] = kwargs.pop(side + 'array')
elif side + 'span' not in kwargs:
kwargs[side + 'span'] = True # spans all rows or columns
panels = _default(panel, panels, '')
legends = _default(legend, legends, '')
colorbars = _default(colorbar, colorbars, '')
# Get panel props
kwargs = _panels_kwargs(panels, colorbars, legends, kwargs,
ncols=ncols, nrows=nrows, figure=True)
# Warnings
axpanels = _default(axpanel, axpanels, '')
axcolorbars = _default(axcolorbar, axcolorbars, '')
axlegends = _default(axlegend, axlegends, '')
axpanels_kw = _default(axpanel_kw, axpanels_kw, {})
axcolorbars_kw = _default(axcolorbar_kw, axcolorbars_kw, {})
axlegends_kw = _default(axlegend_kw, axlegends_kw, {})
if not axpanels and axpanels_kw:
warnings.warn(f'Ignoring axpanels keyword args: {axpanels_kw}')
if not axcolorbars and axcolorbars_kw:
warnings.warn(f'Ignoring axcolorbars keyword args: {axcolorbars_kw}')
if not axlegends and axlegends_kw:
warnings.warn(f'Ignoring axlegends keyword args: {axlegends_kw}')
yformatter = _default(yticklabels, yformatter)
xlocator = _default(xticks, xlocator) # default is AutoLocator, no setting
ylocator = _default(yticks, ylocator)
xminorlocator = _default(xminorticks, xminorlocator) # default is AutoMinorLocator, no setting
yminorlocator = _default(yminorticks, yminorlocator)
# Grid defaults are more complicated
axis = rc.get('axes.grid.axis') # always need this property
grid, which = rc['axes.grid'], rc['axes.grid.which']
if which is not None or grid is not None: # only if *one* was changed recently!
if grid is None:
grid = rc.get('axes.grid')
elif which is None:
which = rc.get('axes.grid.which')
xgrid = _default(xgrid, grid and axis in ('x','both') and which in ('major','both'))
ygrid = _default(ygrid, grid and axis in ('y','both') and which in ('major','both'))
xgridminor = _default(xgridminor, grid and axis in ('x','both') and which in ('minor','both'))
ygridminor = _default(ygridminor, grid and axis in ('y','both') and which in ('minor','both'))
# Weird bug override
# NOTE: Latest matplotlib versions seem to have fixed below bug. For
# now remove warning message, because it is triggered whenever user
# draws a top 'flush' panel.
# if xticklabelloc in ('both','top') and (xlabelloc!='top' or not xlabel): # xtickloc *cannot* be 'top', *only* appears for 'both'
# warnings.warn('This keyword combo causes matplotlib bug where title is not offset from tick labels. Try again with xticklabelloc="bottom" or xlabelloc="top". Defaulting to the latter.')
# xticklabelloc = xlabelloc = 'top'
# Sensible defaults for spine, tick, tick label, and label locations
# NOTE: Allow tick labels to be present without ticks! User may
# want this sometimes! Same goes for spines!
xspineloc = _default(xloc, xspineloc)
yspineloc = _default(yloc, yspineloc)
xtickloc = _default(xtickloc, xspineloc, _rcloc_to_stringloc('x', 'xtick'))
ytickloc = _default(ytickloc, yspineloc, _rcloc_to_stringloc('y', 'ytick'))
def _panel_prop(side, name, defaults):
"""Returns property from the appropriate dictionary, or returns the
default from the rc.subplots category."""
if not isinstance(defaults, tuple):
defaults = 3*(defaults,)
for check,kwargs,default in zip((panels, colorbars, legends), (panels_kw, colorbars_kw, legends_kw), defaults):
if side not in check:
continue
if isinstance(default, str):
default = rc['subplot.' + default]
return _default(kwargs.get(name, None), kwargs.get(side + name, None), default)
`~matplotlib.axes.Axes.legend`. Defaults to ``rc['colorbar.frameon']``.
alpha, linewidth, edgecolor, facecolor : optional
Transparency, edge width, edge color, and face color for the frame.
Defaults to ``rc['colorbar.framealpha']``, ``rc['axes.linewidth']``,
``rc['axes.edgecolor']``, and ``rc['axes.facecolor']``.
**kwargs
Passed to `~proplot.wrappers.colorbar_wrapper`.
"""
# Location
ax, loc = wrappers._get_panel(self, loc)
if loc=='fill':
return ax.colorbar(*args, **kwargs)
# Default props
loc = _default(loc, rc['colorbar.loc'])
extend = units(_default(kwargs.get('extendsize',None), rc['colorbar.extendinset']))
length = units(_default(length, rc['colorbar.length']))/self.width
width = units(_default(width, rc['colorbar.width']))/self.height
pad = units(_default(pad, rc['colorbar.axespad']))
xpad = pad/self.width
ypad = pad/self.height
# Space for labels
if kwargs.get('label', ''):
xspace = 2.4*rc['font.size']/72 + rc['xtick.major.size']/72
else:
xspace = 1.2*rc['font.size']/72 + rc['xtick.major.size']/72
xspace /= self.height
# Get location in axes-relative coordinates
# Bounds are x0, y0, width, height in axes-relative coordinate to start
if loc in ('upper right','ur'):
bounds = (1-xpad-length, 1-ypad-width)
fbounds = (1-2*xpad-length, 1-2*ypad-width-xspace)
elif loc in ('upper left','ul'):