Skip to content

Commit

Permalink
Use FuncFormatter for custom plot units (#655)
Browse files Browse the repository at this point in the history
Relates to: #654
  • Loading branch information
MichaelGrupp authored Apr 21, 2024
1 parent 3067541 commit 2ca7a06
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 3 additions & 2 deletions evo/tools/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
from matplotlib.figure import Figure
from matplotlib.backend_bases import FigureCanvasBase
from matplotlib.collections import LineCollection
from matplotlib.ticker import FuncFormatter
from matplotlib.transforms import Affine2D, Bbox

from evo import EvoException
Expand Down Expand Up @@ -273,11 +274,11 @@ def set_aspect_equal(ax: Axes) -> None:
ax.set_zlim3d([zmean - plot_radius, zmean + plot_radius])


def _get_length_formatter(length_unit: Unit) -> typing.Callable:
def _get_length_formatter(length_unit: Unit) -> FuncFormatter:
def formatter(x, _):
return "{0:g}".format(x / METER_SCALE_FACTORS[length_unit])

return formatter
return FuncFormatter(formatter)


def prepare_axis(fig: Figure, plot_mode: PlotMode = PlotMode.xy,
Expand Down
2 changes: 1 addition & 1 deletion evo/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.26.2
v1.26.3
4 changes: 4 additions & 0 deletions test/cfg/traj/common/plot_specialities.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"save_plot": "tmp/plot.pdf",
"plot_trajectory_length_unit": "mm"
}

0 comments on commit 2ca7a06

Please sign in to comment.