def load_axes(d):
"""Create an axes or subplot from what is returned by
:meth:`inspect_axes`"""
import matplotlib.pyplot as plt
fig = plt.figure(d.pop('fig', None))
proj = d.pop('projection', None)
spines = d.pop('spines', None)
invert_yaxis = d.pop('yaxis_inverted', None)
invert_xaxis = d.pop('xaxis_inverted', None)
if mpl.__version__ >= '2.0' and 'axisbg' in d: # axisbg is depreceated
d['facecolor'] = d.pop('axisbg')
elif mpl.__version__ < '2.0' and 'facecolor' in d:
d['axisbg'] = d.pop('facecolor')
if proj is not None and not isinstance(proj, six.string_types):
proj = getattr(import_module(proj[0]), proj[1])()
if d.pop('is_subplot', None):
grid_spec = mpl.gridspec.GridSpec(*d.pop('grid_spec', (1, 1)))
subplotspec = mpl.gridspec.SubplotSpec(
grid_spec, *d.pop('subplotspec', (1, None)))
return fig.add_subplot(subplotspec, projection=proj, **d)
ret = fig.add_axes(*d.pop('args', []), projection=proj, **d)
if spines is not None:
for key, val in spines.items():
ret.spines[key].update(val)
if invert_xaxis:
if ret.get_xlim()[0] < ret.get_xlim()[1]:
ret.invert_xaxis()
if invert_yaxis:
if ret.get_ylim()[0] < ret.get_ylim()[1]:
ret.invert_yaxis()
return ret
评论列表
文章目录