Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# Also mark formatters and locators as 'default'
if rebuild:
kwdraw = {}
formatter = axis.get_major_formatter()
if formatter is not None: # use functional formatter
kwdraw['fmt'] = formatter
for obj in self._iter_gridlines(objs):
obj.set_visible(False)
array = [False if _ is None else _ for _ in array] # None causes error
objs = getattr(self.projection, method)(
lines, ax=self, latmax=latmax, labels=array, **kwdraw
)
setattr(self, attr, objs)
# Update gridline settings
rc_mode = rc._get_context_mode()
kwlines, kwtext = self._get_gridline_props(
which=which, context=(not rebuild and rc_mode == 2)
)
for obj in self._iter_gridlines(objs):
if isinstance(obj, mtext.Text):
obj.update(kwtext)
else:
obj.update(kwlines)
# Toggle existing gridlines on and off
if grid is not None:
for obj in self._iter_gridlines(objs):
obj.set_visible(grid)
warnings._warn_proplot(
f'Ignoring tight_layout={tight_layout} and '
f'contrained_layout={constrained_layout}. ProPlot uses its '
'own tight layout algorithm, activated by default or with '
'plot.subplots(tight=True).'
)
self._authorized_add_subplot = False
self._is_preprocessing = False
self._is_autoresizing = False
super().__init__(**kwargs)
# Axes sharing and spanning settings
sharex = _not_none(sharex, share, rc['subplots.share'])
sharey = _not_none(sharey, share, rc['subplots.share'])
spanx = _not_none(spanx, span, 0 if sharex == 0 else None, rc['subplots.span'])
spany = _not_none(spany, span, 0 if sharey == 0 else None, rc['subplots.span'])
if spanx and (alignx or align):
warnings._warn_proplot('"alignx" has no effect when spanx=True.')
if spany and (aligny or align):
warnings._warn_proplot('"aligny" has no effect when spany=True.')
alignx = _not_none(alignx, align, rc['subplots.align'])
aligny = _not_none(aligny, align, rc['subplots.align'])
if int(sharex) not in range(4):
raise ValueError(
'Invalid sharing level sharex={value!r}. '
'Axis sharing level can be 0 (share nothing), '
'1 (hide axis labels), '
'2 (share limits and hide axis labels), or '
'3 (share limits and hide axis and tick labels).'
)
if int(sharey) not in range(4):
raise ValueError(
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
# gets blurred where we have shared axes, spanning labels, and
# whatnot. May result in redundant assignments if formatting more than
# one axes, but operations are fast so some redundancy is nbd.
# NOTE: Below kludge prevents changed *figure-wide* settings
# from getting overwritten when user makes a new axes.
fig = self.figure
suptitle = _not_none(figtitle=figtitle, suptitle=suptitle)
if len(fig._axes_main) > 1 and rc._context and rc._context[-1].mode == 1:
kw = {}
else:
kw = rc.fill(
{
'fontsize': 'suptitle.size',
'weight': 'suptitle.weight',
'color': 'suptitle.color',
'fontfamily': 'font.family'
},
context=True,
)
if suptitle or kw:
fig._update_super_title(suptitle, **kw)
# Labels
rlabels = _not_none(rightlabels=rightlabels, rlabels=rlabels)
See also
--------
proplot.config.RcConfigurator.context
proplot.axes.Axes.format
Note
----
If you plot something with a `datetime64 \
`__,
`pandas.Timestamp`, `pandas.DatetimeIndex`, `datetime.date`,
`datetime.time`, or `datetime.datetime` array as the *x* or *y* axis
coordinate, the axis ticks and tick labels will be automatically
formatted as dates.
"""
rc_kw, rc_mode, kwargs = self._parse_format(**kwargs)
with rc.context(rc_kw, mode=rc_mode):
# Background patch
kw_face = rc.fill(
{
'facecolor': 'axes.facecolor',
'alpha': 'axes.alpha'
},
context=True,
)
patch_kw = patch_kw or {}
kw_face.update(patch_kw)
self.patch.update(kw_face)
# No mutable default args
xlabel_kw = xlabel_kw or {}
ylabel_kw = ylabel_kw or {}
xscale_kw = xscale_kw or {}
Resolution of geographic features. For basemap axes, this must be
passed to `~proplot.constructor.Proj`.
%(axes.patch_kw)s
Other parameters
----------------
%(axes.other)s
See also
--------
proplot.axes.Axes.format
proplot.config.RcConfigurator.context
"""
# Format axes
rc_kw, rc_mode, kwargs = self._parse_format(**kwargs)
with rc.context(rc_kw, mode=rc_mode):
# Gridline toggles
grid = rc.get('grid', context=True)
gridminor = rc.get('gridminor', context=True)
longrid = _not_none(longrid, grid)
latgrid = _not_none(latgrid, grid)
longridminor = _not_none(longridminor, gridminor)
latgridminor = _not_none(latgridminor, gridminor)
# Label toggles
labels = _not_none(labels, rc.get('grid.labels', context=True))
lonlabels = _not_none(lonlabels, labels)
latlabels = _not_none(latlabels, labels)
lonarray = self._to_label_array(lonlabels, lon=True)
latarray = self._to_label_array(latlabels, lon=False)
# Update 'maximum latitude'
'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
obj = self._abc_label
abc = rc.get('abc', context=True)
if abc is not None:
obj.set_text(self._abc_text if bool(abc) else '')
# Apply new settings
loc = self._loc_translate(None, 'abc')
loc_prev = self._abc_loc
if loc is None:
loc = loc_prev
kw = sanitize_kw(kw, loc)
if loc_prev is None or loc != loc_prev:
obj_ref = self._get_title(loc)
obj.set_ha(obj_ref.get_ha())
obj.set_va(obj_ref.get_va())
obj.set_transform(obj_ref.get_transform())
obj.set_position(obj_ref.get_position())
obj.update(kw)
'labelsize': 'tick.labelsize',
'color': x + 'tick.color',
},
context=True,
)
if color:
kw['color'] = color
kw['labelcolor'] = color
# Tick label direction and rotation
if tickdir == 'in': # ticklabels should be much closer
kw['pad'] = 1.0
if ticklabeldir == 'in': # put tick labels inside the plot
tickdir = 'in'
kw['pad'] = -rc[f'{x}tick.major.size'] - rc[f'{x}tick.major.pad']
kw['pad'] -= rc._scale_font(rc[f'{x}tick.labelsize'])
if tickdir is not None:
kw['direction'] = tickdir
axis.set_tick_params(which='both', **kw)
# Settings that can't be controlled by set_tick_params
# Also set rotation and alignment here
kw = rc.fill(
{
'fontfamily': 'font.family',
'weight': 'tick.labelweight'
},
context=True,
)
if rotation is not None:
kw = {'rotation': rotation}
if x == 'x':
def _default_space(key, share=0, pad=None):
"""
Return suitable default spacing given a shared axes setting.
"""
# Pull out sizes
outerpad = rc['subplots.pad'] # TODO: rename these to outerpad, innerpad
innerpad = rc['subplots.axpad']
xtick = rc['xtick.major.size']
ytick = rc['ytick.major.size']
xtickpad = rc['xtick.major.pad']
ytickpad = rc['ytick.major.pad']
xticklabel = rc._scale_font(rc['xtick.labelsize'])
yticklabel = 3 * rc._scale_font(rc['ytick.labelsize'])
label = rc._scale_font(rc['axes.labelsize'])
title = rc._scale_font(rc['axes.titlesize'])
titlepad = rc['axes.titlepad']
# Get suitable size for various spaces
if key == 'left':
space = units(_not_none(pad, outerpad)) + (
ytick + yticklabel + ytickpad + label
) / 72
elif key == 'right':
space = units(_not_none(pad, outerpad))
elif key == 'bottom':
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'
f'Invalid family {family!r}. Options are: '
+ ', '.join(map(repr, options)) + '.'
)
if family == 'tex-gyre':
family_fonts = (
'TeX Gyre Adventor',
'TeX Gyre Bonum',
'TeX Gyre Cursor',
'TeX Gyre Chorus',
'TeX Gyre Heros',
'TeX Gyre Pagella',
'TeX Gyre Schola',
'TeX Gyre Termes',
)
else:
family_fonts = rc['font.' + family]
args = (
*args, *sorted({
font.name for font in mfonts.fontManager.ttflist
if font.name in family_fonts
})
)
# Text
if text is None:
text = (
'the quick brown fox jumps over a lazy dog' '\n'
'THE QUICK BROWN FOX JUMPS OVER A LAZY DOG' '\n'
'(0) + {1\N{DEGREE SIGN}} \N{MINUS SIGN} [2*] - <3> / 4,0 '
r'$\geq\gg$ 5.0 $\leq\ll$ ~6 $\times$ 7 '
r'$\equiv$ 8 $\approx$ 9 $\propto$' '\n'
r'$\alpha\beta$ $\Gamma\gamma$ $\Delta\delta$ '