# Buggy code
def __call__(self, plot):
    from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar

    # Callback only works for plots with axis ratios of 1
    xsize = plot.xlim[1] - plot.xlim[0]
    if plot.aspect != 1.0:
        raise NotImplementedError(
            "Scale callback has only been implemented for plots with no "
            "aspect ratio scaling. (aspect = {%s})".format(plot._aspect)
        )

    # Setting pos overrides corner argument
    if self.pos is None:
        if self.corner == "upper_left":
            self.pos = (0.11, 0.952)
        elif self.corner == "upper_right":
            self.pos = (0.89, 0.952)
        elif self.corner == "lower_left":
            self.pos = (0.11, 0.052)
        elif self.corner == "lower_right":
            self.pos = (0.89, 0.052)
        elif self.corner is None:
            self.pos = (0.5, 0.5)
        else:
            raise SyntaxError(
                "Argument 'corner' must be set to "
                "'upper_left', 'upper_right', 'lower_left', "
                "'lower_right', or None"
            )

    # When identifying a best fit distance unit, do not allow scale marker
    # to be greater than max_frac fraction of xaxis or under min_frac
    # fraction of xaxis
    max_scale = self.max_frac * xsize
    min_scale = self.min_frac * xsize

    if self.coeff is None:
        self.coeff = 1.0

    # If no units are set, then identify a best fit distance unit
    if self.unit is None:
        min_scale = plot.ds.get_smallest_appropriate_unit(
            min_scale, return_quantity=True
        )
        max_scale = plot.ds.get_smallest_appropriate_unit(
            max_scale, return_quantity=True
        )
        self.coeff = max_scale.v
        self.unit = max_scale.units
    self.scale = YTQuantity(self.coeff, self.unit)
    text = "{scale} {units}".format(scale=int(self.coeff), units=self.unit)
    image_scale = (
        plot.frb.convert_distance_x(self.scale) / plot.frb.convert_distance_x(xsize)
    ).v

    size_vertical = self.size_bar_args.pop("size_vertical", 0.005)
    fontproperties = self.size_bar_args.pop(
        "fontproperties", plot.font_properties.copy()
    )
    frameon = self.size_bar_args.pop("frameon", self.draw_inset_box)
    # FontProperties instances use set_<property>() setter functions
    for key, val in self.text_args.items():
        setter_func = "set_" + key
        try:
            getattr(fontproperties, setter_func)(val)
        except AttributeError:
            raise AttributeError(
                "Cannot set text_args keyword "
                "to include '%s' because MPL's fontproperties object does "
                "not contain function '%s'." % (key, setter_func)
            )

    # this "anchors" the size bar to a box centered on self.pos in axis
    # coordinates
    self.size_bar_args["bbox_to_anchor"] = self.pos
    self.size_bar_args["bbox_transform"] = plot._axes.transAxes

    bar = AnchoredSizeBar(
        plot._axes.transAxes,
        image_scale,
        text,
        10,
        size_vertical=size_vertical,
        fontproperties=fontproperties,
        frameon=frameon,
        **self.size_bar_args,
    )

    bar.patch.set(**self.inset_box_args)

    plot._axes.add_artist(bar)

    return plot


# Traceback (AttributeError)
Traceback (most recent call last):
File "/usr/local/lib/python3.5/site-packages/yt/visualization/plot_window.py", line 1007, in run_callbacks
callback(cbw)
File "/usr/local/lib/python3.5/site-packages/yt/visualization/plot_modifications.py", line 54, in _check_geometry
return func(self, plot)
File "/usr/local/lib/python3.5/site-packages/yt/visualization/plot_modifications.py", line 2084, in __call__
"aspect ratio scaling. (aspect = {%s})".format(plot._aspect))
AttributeError: 'CallbackWrapper' object has no attribute '_aspect'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "test.py", line 7, in <module>
slc.save()
File "/usr/local/lib/python3.5/site-packages/yt/visualization/plot_container.py", line 78, in newfunc
args[0]._setup_plots()
File "/usr/local/lib/python3.5/site-packages/yt/visualization/plot_window.py", line 956, in _setup_plots
self.run_callbacks()
File "/usr/local/lib/python3.5/site-packages/yt/visualization/plot_window.py", line 1013, in run_callbacks
sys.exc_info()[2])
File "/usr/local/lib/python3.5/site-packages/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/usr/local/lib/python3.5/site-packages/yt/visualization/plot_window.py", line 1007, in run_callbacks
callback(cbw)
File "/usr/local/lib/python3.5/site-packages/yt/visualization/plot_modifications.py", line 54, in _check_geometry
return func(self, plot)
File "/usr/local/lib/python3.5/site-packages/yt/visualization/plot_modifications.py", line 2084, in __call__
"aspect ratio scaling. (aspect = {%s})".format(plot._aspect))
yt.utilities.exceptions.YTPlotCallbackError: annotate_scale callback failed with the following error: 'CallbackWrapper' object has no attribute '_aspect'

# Fixed code
def __call__(self, plot):
    from mpl_toolkits.axes_grid1.anchored_artists import AnchoredSizeBar

    # Callback only works for plots with axis ratios of 1
    xsize = plot.xlim[1] - plot.xlim[0]

    # Setting pos overrides corner argument
    if self.pos is None:
        if self.corner == "upper_left":
            self.pos = (0.11, 0.952)
        elif self.corner == "upper_right":
            self.pos = (0.89, 0.952)
        elif self.corner == "lower_left":
            self.pos = (0.11, 0.052)
        elif self.corner == "lower_right":
            self.pos = (0.89, 0.052)
        elif self.corner is None:
            self.pos = (0.5, 0.5)
        else:
            raise SyntaxError(
                "Argument 'corner' must be set to "
                "'upper_left', 'upper_right', 'lower_left', "
                "'lower_right', or None"
            )

    # When identifying a best fit distance unit, do not allow scale marker
    # to be greater than max_frac fraction of xaxis or under min_frac
    # fraction of xaxis
    max_scale = self.max_frac * xsize
    min_scale = self.min_frac * xsize

    if self.coeff is None:
        self.coeff = 1.0

    # If no units are set, then identify a best fit distance unit
    if self.unit is None:
        min_scale = plot.ds.get_smallest_appropriate_unit(
            min_scale, return_quantity=True
        )
        max_scale = plot.ds.get_smallest_appropriate_unit(
            max_scale, return_quantity=True
        )
        self.coeff = max_scale.v
        self.unit = max_scale.units
    self.scale = YTQuantity(self.coeff, self.unit)
    text = "{scale} {units}".format(scale=int(self.coeff), units=self.unit)
    image_scale = (
        plot.frb.convert_distance_x(self.scale) / plot.frb.convert_distance_x(xsize)
    ).v
    size_vertical = self.size_bar_args.pop("size_vertical", 0.005 * plot.aspect)
    fontproperties = self.size_bar_args.pop(
        "fontproperties", plot.font_properties.copy()
    )
    frameon = self.size_bar_args.pop("frameon", self.draw_inset_box)
    # FontProperties instances use set_<property>() setter functions
    for key, val in self.text_args.items():
        setter_func = "set_" + key
        try:
            getattr(fontproperties, setter_func)(val)
        except AttributeError:
            raise AttributeError(
                "Cannot set text_args keyword "
                "to include '%s' because MPL's fontproperties object does "
                "not contain function '%s'." % (key, setter_func)
            )

    # this "anchors" the size bar to a box centered on self.pos in axis
    # coordinates
    self.size_bar_args["bbox_to_anchor"] = self.pos
    self.size_bar_args["bbox_transform"] = plot._axes.transAxes

    bar = AnchoredSizeBar(
        plot._axes.transAxes,
        image_scale,
        text,
        10,
        size_vertical=size_vertical,
        fontproperties=fontproperties,
        frameon=frameon,
        **self.size_bar_args,
    )

    bar.patch.set(**self.inset_box_args)

    plot._axes.add_artist(bar)

    return plot