4 from __future__
import division
6 import matplotlib.pyplot
as plt
10 from jsk_recognition_msgs.msg
import Spectrum
17 self.
fig = plt.figure(figsize=(8, 5))
18 self.fig.suptitle(
'Spectrum plot', size=12)
19 self.fig.subplots_adjust(left=0.1, right=0.95, top=0.90, bottom=0.1,
20 wspace=0.2, hspace=0.6)
21 self.
ax = self.fig.add_subplot(1, 1, 1)
23 self.ax.set_xlabel(
'Frequency [Hz]', fontsize=12)
24 self.ax.set_ylabel(
'Amplitude', fontsize=12)
25 self.line, = self.ax.plot([0, 0], label=
'Amplitude of Spectrum')
28 '~spectrum', Spectrum, self.
_cb, queue_size=1000)
32 self.
amp = np.array(msg.amplitude)
33 self.
freq = np.array(msg.frequency)
34 self.line.set_data(self.
freq, self.
amp)
35 self.ax.set_xlim((self.freq.min(), self.freq.max()))
36 self.ax.set_ylim((0.0, 20))
37 self.ax.legend(loc=
'upper right')
40 if __name__ ==
'__main__':
41 rospy.init_node(
'spectrum_plot')
43 while not rospy.is_shutdown():