Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# No mutable default args
xlabel_kw = xlabel_kw or {}
ylabel_kw = ylabel_kw or {}
xscale_kw = xscale_kw or {}
yscale_kw = yscale_kw or {}
xlocator_kw = xlocator_kw or {}
ylocator_kw = ylocator_kw or {}
xformatter_kw = xformatter_kw or {}
yformatter_kw = yformatter_kw or {}
xminorlocator_kw = xminorlocator_kw or {}
yminorlocator_kw = yminorlocator_kw or {}
# Flexible keyword args, declare defaults
xmargin = _not_none(xmargin, rc.get('axes.xmargin', context=True))
ymargin = _not_none(ymargin, rc.get('axes.ymargin', context=True))
xtickdir = _not_none(xtickdir, rc.get('xtick.direction', context=True))
ytickdir = _not_none(ytickdir, rc.get('ytick.direction', context=True))
xformatter = _not_none(xformatter=xformatter, xticklabels=xticklabels)
yformatter = _not_none(yformatter=yformatter, yticklabels=yticklabels)
xlocator = _not_none(xlocator=xlocator, xticks=xticks)
ylocator = _not_none(ylocator=ylocator, yticks=yticks)
xtickminor = _not_none(
xtickminor, rc.get('xtick.minor.visible', context=True)
)
ytickminor = _not_none(
ytickminor, rc.get('ytick.minor.visible', context=True)
)
xminorlocator = _not_none(
xminorlocator=xminorlocator, xminorticks=xminorticks,
)
yminorlocator = _not_none(
yminorlocator=yminorlocator, yminorticks=yminorticks,
# No mutable default args
xlabel_kw = xlabel_kw or {}
ylabel_kw = ylabel_kw or {}
xscale_kw = xscale_kw or {}
yscale_kw = yscale_kw or {}
xlocator_kw = xlocator_kw or {}
ylocator_kw = ylocator_kw or {}
xformatter_kw = xformatter_kw or {}
yformatter_kw = yformatter_kw or {}
xminorlocator_kw = xminorlocator_kw or {}
yminorlocator_kw = yminorlocator_kw or {}
# Flexible keyword args, declare defaults
xmargin = _not_none(xmargin, rc.get('axes.xmargin', context=True))
ymargin = _not_none(ymargin, rc.get('axes.ymargin', context=True))
xtickdir = _not_none(xtickdir, rc.get('xtick.direction', context=True))
ytickdir = _not_none(ytickdir, rc.get('ytick.direction', context=True))
xformatter = _not_none(xformatter=xformatter, xticklabels=xticklabels)
yformatter = _not_none(yformatter=yformatter, yticklabels=yticklabels)
xlocator = _not_none(xlocator=xlocator, xticks=xticks)
ylocator = _not_none(ylocator=ylocator, yticks=yticks)
xtickminor = _not_none(
xtickminor, rc.get('xtick.minor.visible', context=True)
)
ytickminor = _not_none(
ytickminor, rc.get('ytick.minor.visible', context=True)
)
xminorlocator = _not_none(
xminorlocator=xminorlocator, xminorticks=xminorticks,
)
yminorlocator = _not_none(
'fontfamily': 'font.family',
},
context=True
)
kwb = rc.fill(
{
'border': 'abc.border',
'borderwidth': 'abc.borderwidth',
},
context=True,
)
self._abc_border_kwargs.update(kwb)
kw.update(self._abc_border_kwargs)
# Label format
abcstyle = rc.get('abc.style', context=True) # 1st run, or changed
if abcstyle and self.number is not None:
if not isinstance(abcstyle, str) or (
'a' not in abcstyle and 'A' not in abcstyle
):
raise ValueError(
f'Invalid abcstyle {abcstyle!r}. '
'Must include letter "a" or "A".'
)
# Build abc labels as a...z...aa...zz...aaa...zzz
# Permit abcstyles with arbitrary counts of A's
nabc, iabc = divmod(self.number - 1, 26)
text = (nabc + 1) * ABC_STRING[iabc]
text = abcstyle.replace('a', text).replace('A', text.upper())
self._abc_text = text
# Apply text
lonminorlines_kw=lonminorlines_kw,
default={},
)
locator = constructor.Locator(lonminorlocator, **lonminorlocator_kw)
self._lonaxis.set_minor_locator(locator)
if latminorlocator is not None:
latminorlocator_kw = _not_none(
latminorlocator_kw=latminorlocator_kw,
latminorlines_kw=latminorlines_kw,
default={},
)
locator = constructor.Locator(latminorlocator, **latminorlocator_kw)
self._lataxis.set_minor_locator(locator)
# Update formatters
loninline = _not_none(loninline, rc.get('grid.loninline', context=True))
latinline = _not_none(latinline, rc.get('grid.latinline', context=True))
labelpad = _not_none(labelpad, rc.get('grid.pad', context=True))
rotatelabels = _not_none(
rotatelabels, rc.get('grid.rotatelabels', context=True)
)
dms = _not_none(dms, rc.get('grid.dmslabels', context=True))
nsteps = _not_none(nsteps, rc.get('grid.nsteps', context=True))
if lonformatter is not None:
lonformatter_kw = lonformatter_kw or {}
formatter = constructor.Formatter(lonformatter, **lonformatter_kw)
self._lonaxis.set_major_formatter(formatter)
if latformatter is not None:
latformatter_kw = latformatter_kw or {}
formatter = constructor.Formatter(latformatter, **latformatter_kw)
self._lataxis.set_major_formatter(formatter)
if dms is not None: # harmless if these are not GeoLocators
"""
if x == 'x':
top = rc.get(f'{string}.top', context=True)
bottom = rc.get(f'{string}.bottom', context=True)
if top is None and bottom is None:
return None
elif top and bottom:
return 'both'
elif top:
return 'top'
elif bottom:
return 'bottom'
else:
return 'neither'
else:
left = rc.get(f'{string}.left', context=True)
right = rc.get(f'{string}.right', context=True)
if left is None and right is None:
return None
elif left and right:
return 'both'
elif left:
return 'left'
elif right:
return 'right'
else:
return 'neither'
The `abc`, `abcstyle`, `abcloc`, and `titleloc` keyword arguments are
actually :ref:`configuration settings ` that are temporarily
changed by the call to `~proplot.config.RcConfigurator.context`. They
are also documented here because it is very common to change them with
`~Axes.format`.
See also
--------
proplot.config.RcConfigurator.context
proplot.axes.CartesianAxes.format
proplot.axes.PolarAxes.format
proplot.axes.GeoAxes.format
"""
# Misc axes settings
# TODO: Add more settings to this?
cycle = rc.get('axes.prop_cycle', context=True)
if cycle is not None:
self.set_prop_cycle(cycle)
# Figure patch (for some reason needs to be re-asserted even if
# declared before figure is drawn)
kw = rc.fill({'facecolor': 'figure.facecolor'}, context=True)
self.figure.patch.update(kw)
if abovetop is not None:
self._above_top_panels = abovetop
pad = rc.get('axes.titlepad', context=True)
if pad is not None:
self._set_title_offset_trans(pad)
self._title_pad = pad
# Super title
# NOTE: These are actually *figure-wide* settings, but that line
"""
# NOTE: The e.g. cfeature.COASTLINE features are just for convenience,
# lo res versions. Use NaturalEarthFeature instead.
# WARNING: Seems cartopy features cannot be updated! Updating _kwargs
# attribute does *nothing*.
reso = rc['reso'] # resolution cannot be changed after feature created
try:
reso = constructor.CARTOPY_RESOS[reso]
except KeyError:
raise ValueError(
f'Invalid resolution {reso!r}. Options are: '
+ ', '.join(map(repr, constructor.CARTOPY_RESOS)) + '.'
)
for name, args in constructor.CARTOPY_FEATURES.items():
# Draw feature or toggle feature off
b = rc.get(name, context=True)
attr = f'_{name}_feature'
feat = getattr(self, attr, None)
drawn = feat is not None # if exists, apply *updated* settings
if b is not None:
if not b:
if drawn: # toggle existing feature off
feat.set_visible(False)
else:
if not drawn:
feat = cfeature.NaturalEarthFeature(*args, reso)
feat = self.add_feature(feat) # convert to FeatureArtist
# Update artist attributes (FeatureArtist._kwargs used back to v0.5).
# For 'lines', need to specify edgecolor and facecolor
# See: https://github.com/SciTools/cartopy/issues/803
if feat is not None:
default={},
)
locator = constructor.Locator(lonminorlocator, **lonminorlocator_kw)
self._lonaxis.set_minor_locator(locator)
if latminorlocator is not None:
latminorlocator_kw = _not_none(
latminorlocator_kw=latminorlocator_kw,
latminorlines_kw=latminorlines_kw,
default={},
)
locator = constructor.Locator(latminorlocator, **latminorlocator_kw)
self._lataxis.set_minor_locator(locator)
# Update formatters
loninline = _not_none(loninline, rc.get('grid.loninline', context=True))
latinline = _not_none(latinline, rc.get('grid.latinline', context=True))
labelpad = _not_none(labelpad, rc.get('grid.pad', context=True))
rotatelabels = _not_none(
rotatelabels, rc.get('grid.rotatelabels', context=True)
)
dms = _not_none(dms, rc.get('grid.dmslabels', context=True))
nsteps = _not_none(nsteps, rc.get('grid.nsteps', context=True))
if lonformatter is not None:
lonformatter_kw = lonformatter_kw or {}
formatter = constructor.Formatter(lonformatter, **lonformatter_kw)
self._lonaxis.set_major_formatter(formatter)
if latformatter is not None:
latformatter_kw = latformatter_kw or {}
formatter = constructor.Formatter(latformatter, **latformatter_kw)
self._lataxis.set_major_formatter(formatter)
if dms is not None: # harmless if these are not GeoLocators
self._lonaxis.get_major_formatter()._dms = dms
Get dictionaries of gridline properties for lines and text.
"""
# Line properties
# WARNING: Here we use apply existing *matplotlib* rc param to brand new
# *proplot* setting. So if rc mode is 1 (first format call) use context=False.
key = 'grid' if which == 'major' else 'gridminor'
kwlines = rc.fill(
{
'alpha': f'{key}.alpha',
'color': f'{key}.color',
'linewidth': f'{key}.linewidth',
'linestyle': f'{key}.linestyle',
},
context=context,
)
axisbelow = rc.get('axes.axisbelow', context=True)
if axisbelow is not None:
kwlines['zorder'] = self._axis_below_to_zorder(axisbelow)
# Text properties
kwtext = {}
if which == 'major':
kwtext = rc.fill(
{
'color': f'{key}.labelcolor',
'fontsize': f'{key}.labelsize',
'weight': f'{key}.labelweight',
},
context=context,
)
return kwlines, kwtext