Skip to content

Commit

Permalink
Merge pull request #2989 from brittonsmith/scale
Browse files Browse the repository at this point in the history
[bugfix] Use axes unit in scale bar if set by user.
  • Loading branch information
matthewturk committed Dec 23, 2020
2 parents df752d3 + 4fb42b1 commit 425513d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
1 change: 1 addition & 0 deletions yt/visualization/base_plot_types.py
Expand Up @@ -53,6 +53,7 @@ def __init__(self, viewer, window_plot, frb, field, font_properties, font_color)
self.ds = frb.ds
self.xlim = viewer.xlim
self.ylim = viewer.ylim
self._axes_unit_names = viewer._axes_unit_names
if "OffAxisSlice" in viewer._plot_type:
self._type_name = "CuttingPlane"
else:
Expand Down
25 changes: 15 additions & 10 deletions yt/visualization/plot_modifications.py
Expand Up @@ -2702,17 +2702,22 @@ def __call__(self, plot):
max_scale = self.max_frac * xsize
min_scale = self.min_frac * xsize

# If no units are set, then identify a best fit distance unit
# If no units are set, pick something sensible.
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
)
if self.coeff is None:
self.coeff = max_scale.v
self.unit = max_scale.units
# User has set the axes units and supplied a coefficient.
if plot._axes_unit_names is not None and self.coeff is not None:
self.unit = plot._axes_unit_names[0]
# Nothing provided; identify a best fit distance unit.
else:
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
)
if self.coeff is None:
self.coeff = max_scale.v
self.unit = max_scale.units
elif self.coeff is None:
self.coeff = 1
self.scale = plot.ds.quan(self.coeff, self.unit)
Expand Down

0 comments on commit 425513d

Please sign in to comment.