Skip to content

Commit a394972

Browse files
author
Enrique Fernández Perdomo
committed
Merge pull request #10 from clearpathrobotics/add_plot_style_arg
Add plot style arg
2 parents 4212779 + 041a3d7 commit a394972

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

bag_tools/scripts/plot.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,11 +411,12 @@ 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', bag_time=False):
414+
def __init__(self, bags, topics, plot_arrays=True, plot_headers=True, plot_format='png', plot_style='.-', bag_time=False):
415415
self._bags = bags
416416
self._plot_arrays = plot_arrays
417417
self._plot_headers = plot_headers
418418
self._plot_format = plot_format
419+
self._plot_style = plot_style
419420
self._bag_time = bag_time
420421

421422
self._bag_topic_helpers = {}
@@ -507,15 +508,15 @@ def __init__(self, bags, topics, plot_arrays=True, plot_headers=True, plot_forma
507508
ax.set_color_cycle([plt.cm.rainbow(i) for i in numpy.linspace(0, 1, len(values))])
508509

509510
for topic in plottable_topics:
510-
plt.plot(times[topic], values[topic])
511+
plt.plot(times[topic], values[topic], self._plot_style)
511512

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

514515
plt.savefig(bag.replace('.bag', '') + '.' + self._plot_format)
515516

516517
plt.close(fig)
517518
except OverflowError as e:
518-
rospy.logerr('%s: Failed to save plot as %s image file (try other format, e.g. svg): %s', filename, self._plot_format, e.message)
519+
rospy.logerr('Failed to save plot as %s image file (try other format, e.g. svg): %s', self._plot_format, e.message)
519520

520521
def get_plot_fields(self, topic_name):
521522
"""
@@ -614,12 +615,13 @@ def get_plot_fields(self, topic_name):
614615
parser.add_argument('--noarr', help='do not plot array fields', action='store_true')
615616
parser.add_argument('--nohdr', help='do not plot header fields', action='store_true')
616617
parser.add_argument('--plot_format', help='output plot format', default='png')
618+
parser.add_argument('--plot_style', help='output plot style', default='.-')
617619
parser.add_argument('--bag_time', help='use bag time instead of msg header time', action='store_true')
618620

619621
args = parser.parse_args()
620622

621623
try:
622-
BagTopicPlotter(args.bags, args.topics, not args.noarr, not args.nohdr, args.plot_format, args.bag_time)
624+
BagTopicPlotter(args.bags, args.topics, not args.noarr, not args.nohdr, args.plot_format, args.plot_style, args.bag_time)
623625
except Exception, e:
624626
import traceback
625627
traceback.print_exc()

0 commit comments

Comments
 (0)