Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
# use default plot settings
figsize = (SETTINGS.plot_figsize[0], SETTINGS.plot_figsize[1])
use_cmap = SETTINGS.plot_multi_cmap.lower() != "none"
colormap = SETTINGS.plot_multi_cmap if use_cmap else None
linestyles = ["-o" for x in args.result_files
] if args.plot_markers else None
# labels according to first dataset
if "xlabel" in df.loc["info"].index and not df.loc[
"info", "xlabel"].isnull().values.any():
index_label = df.loc["info", "xlabel"][0]
else:
index_label = "$t$ (s)" if common_index else "index"
metric_label = df.loc["info", "label"][0]
plot_collection = plot.PlotCollection(first_title)
# raw value plot
fig_raw = plt.figure(figsize=figsize)
# handle NaNs from concat() above
error_df.interpolate(method="index", limit_area="inside").plot(
ax=fig_raw.gca(), colormap=colormap, style=linestyles,
title=first_title, alpha=SETTINGS.plot_trajectory_alpha)
plt.xlabel(index_label)
plt.ylabel(metric_label)
plt.legend(frameon=True)
plot_collection.add_figure("raw", fig_raw)
# statistics plot
if SETTINGS.plot_statistics:
fig_stats = plt.figure(figsize=figsize)
include = df.loc["stats"].index.isin(SETTINGS.plot_statistics)
if any(include):
args = main_parser.parse_args()
from evo.tools import log, plot, user
log.configure_logging(verbose=True)
if not args.title:
title = os.path.basename(args.in_file)
else:
title = args.title
if not args.no_warnings:
logger.warning(
"This tool is experimental and not guranteed to work.\nOnly works "
"if the same plot settings are used as for serialization.\n"
"If not, try: evo_config show/set \n" + SEP)
plot_collection = plot.PlotCollection(title, deserialize=args.in_file)
logger.debug("Deserialized PlotCollection: " + str(plot_collection))
plot_collection.show()
if args.serialize_plot:
logger.debug(SEP)
plot_collection.serialize(args.serialize_plot,
confirm_overwrite=not args.no_warnings)
if args.save_plot:
logger.debug(SEP)
plot_collection.export(args.save_plot,
confirm_overwrite=not args.no_warnings)
if args.to_html:
import mpld3
logger.debug(SEP + "\nhtml export\n")
for name, fig in plot_collection.figures.items():
html = mpld3.fig_to_html(fig)
"ref_name": ref_name,
"title": title,
"xlabel": "{} sub-sequences ({})".format(mode, bin_unit.value)
})
rpe_for_each_result.add_stats({bin: result for bin, result in zip(bins, results)})
# TODO use a more suitable name than seconds
rpe_for_each_result.add_np_array("seconds_from_start", bins)
rpe_for_each_result.add_np_array("error_array", results)
logger.debug(SEP)
logger.info(rpe_for_each_result.pretty_str())
if show_plot or save_plot or serialize_plot:
from evo.tools import plot
import matplotlib.pyplot as plt
plot_collection = plot.PlotCollection(title)
fig = plt.figure(figsize=(SETTINGS.plot_figsize[0], SETTINGS.plot_figsize[1]))
plot.error_array(fig, results, x_array=bins,
name="mean RPE" + (" (" + rpe_unit.value + ")") if rpe_unit else "",
marker="o", title=title,
xlabel=mode + " sub-sequences " + " (" + bin_unit.value + ")")
# info text
if SETTINGS.plot_info_text and est_name and ref_name:
ax = fig.gca()
ax.text(0, -0.12, "estimate: " + est_name + "\nreference: " + ref_name,
transform=ax.transAxes, fontsize=8, color="gray")
plt.title(title)
plot_collection.add_figure("raw", fig)
if show_plot:
plot_collection.show()
if save_plot:
plot_collection.export(save_plot, confirm_overwrite=not no_warnings)
print_compact_name = not args.subcommand == "bag"
for name, traj in trajectories.items():
print_traj_info(name, traj, args.verbose, args.full_check,
print_compact_name)
if args.ref:
print_traj_info(args.ref, ref_traj, args.verbose, args.full_check,
print_compact_name)
if args.plot or args.save_plot or args.serialize_plot:
import numpy as np
from evo.tools import plot
import matplotlib.pyplot as plt
import matplotlib.cm as cm
plot_collection = plot.PlotCollection("evo_traj - trajectory plot")
fig_xyz, axarr_xyz = plt.subplots(3, sharex="col", figsize=tuple(
SETTINGS.plot_figsize))
fig_rpy, axarr_rpy = plt.subplots(3, sharex="col", figsize=tuple(
SETTINGS.plot_figsize))
fig_traj = plt.figure(figsize=tuple(SETTINGS.plot_figsize))
plot_mode = plot.PlotMode[args.plot_mode]
ax_traj = plot.prepare_axis(fig_traj, plot_mode)
# for x-axis alignment starting from 0 with --plot_relative_time
start_time = None
if args.ref:
if isinstance(ref_traj, trajectory.PoseTrajectory3D) \
and args.plot_relative_time:
start_time = ref_traj.timestamps[0]
traj_ref, traj_est = sync.associate_trajectories(traj_ref, traj_est)
traj_est = trajectory.align_trajectory(traj_est, traj_ref, correct_scale=False)
print("calculating APE")
data = (traj_ref, traj_est)
ape_metric = metrics.APE(metrics.PoseRelation.translation_part)
ape_metric.process_data(data)
ape_statistics = ape_metric.get_all_statistics()
print("mean:", ape_statistics["mean"])
print("loading plot modules")
from evo.tools import plot
import matplotlib.pyplot as plt
print("plotting")
plot_collection = plot.PlotCollection("Example")
# metric values
fig_1 = plt.figure(figsize=(8, 8))
plot.error_array(fig_1, ape_metric.error, statistics=ape_statistics,
name="APE", title=str(ape_metric))
plot_collection.add_figure("raw", fig_1)
# trajectory colormapped with error
fig_2 = plt.figure(figsize=(8, 8))
plot_mode = plot.PlotMode.xy
ax = plot.prepare_axis(fig_2, plot_mode)
plot.traj(ax, plot_mode, traj_ref, '--', 'gray', 'reference')
plot.traj_colormap(
ax, traj_est, ape_metric.error, plot_mode, min_map=ape_statistics["min"],
max_map=ape_statistics["max"], title="APE mapped onto trajectory")
plot_collection.add_figure("traj (error)", fig_2)
plot.traj_colormap(ax, traj_est, result.np_arrays["error_array"],
plot_mode, min_map=args.plot_colormap_min,
max_map=args.plot_colormap_max,
title="Error mapped onto trajectory")
plot.draw_coordinate_axes(ax, traj_est, plot_mode,
SETTINGS.plot_axis_marker_scale)
if SETTINGS.plot_pose_correspondences:
plot.draw_correspondence_edges(
ax, traj_est, traj_ref, plot_mode,
style=SETTINGS.plot_pose_correspondences_linestyle,
color=SETTINGS.plot_reference_color,
alpha=SETTINGS.plot_reference_alpha)
fig2.axes.append(ax)
plot_collection = plot.PlotCollection(result.info["title"])
plot_collection.add_figure("raw", fig1)
plot_collection.add_figure("map", fig2)
if args.plot:
plot_collection.show()
if args.save_plot:
plot_collection.export(args.save_plot,
confirm_overwrite=not args.no_warnings)
if args.serialize_plot:
logger.debug(SEP)
plot_collection.serialize(args.serialize_plot,
confirm_overwrite=not args.no_warnings)