Skip to content

Commit 6677cdf

Browse files
committed
bag_tools/scripts/plot.py: add option to append a suffix to the output filename
1 parent 581994e commit 6677cdf

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

bag_tools/scripts/plot.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,13 +411,14 @@ def get_data(self, msg):
411411

412412

413413
class BagTopicPlotter:
414-
def __init__(self, bags, topics, plot_arrays=True, plot_headers=True, plot_format='png', plot_style='.-', bag_time=False):
414+
def __init__(self, bags, topics, plot_arrays=True, plot_headers=True, plot_format='png', plot_style='.-', bag_time=False, out_suffix = ''):
415415
self._bags = bags
416416
self._plot_arrays = plot_arrays
417417
self._plot_headers = plot_headers
418418
self._plot_format = plot_format
419419
self._plot_style = plot_style
420420
self._bag_time = bag_time
421+
self._out_suffix = out_suffix
421422

422423
self._bag_topic_helpers = {}
423424
for bag in self._bags:
@@ -512,7 +513,7 @@ def __init__(self, bags, topics, plot_arrays=True, plot_headers=True, plot_forma
512513

513514
plt.legend(plottable_topics, loc=0)
514515

515-
plt.savefig(bag.replace('.bag', '') + '.' + self._plot_format)
516+
plt.savefig(bag.replace('.bag', '') + self._out_suffix + '.' + self._plot_format)
516517

517518
plt.close(fig)
518519
except OverflowError as e:
@@ -617,11 +618,12 @@ def get_plot_fields(self, topic_name):
617618
parser.add_argument('--plot_format', help='output plot format', default='png')
618619
parser.add_argument('--plot_style', help='output plot style', default='.-')
619620
parser.add_argument('--bag_time', help='use bag time instead of msg header time', action='store_true')
621+
parser.add_argument('--out_suffix', help='output suffix', default='')
620622

621623
args = parser.parse_args()
622624

623625
try:
624-
BagTopicPlotter(args.bags, args.topics, not args.noarr, not args.nohdr, args.plot_format, args.plot_style, args.bag_time)
626+
BagTopicPlotter(args.bags, args.topics, not args.noarr, not args.nohdr, args.plot_format, args.plot_style, args.bag_time, args.out_suffix)
625627
except Exception, e:
626628
import traceback
627629
traceback.print_exc()

0 commit comments

Comments
 (0)