4 from __future__ 
import division
 
    7 from jsk_topic_tools 
import ConnectionBasedTransport
 
   11 import matplotlib.pyplot 
as plt
 
   14 import sensor_msgs.msg
 
   16 from jsk_recognition_msgs.msg 
import Spectrum
 
   18 from audio_to_spectrogram 
import convert_matplotlib_to_img
 
   25         self.
min_amp = rospy.get_param(
'~min_amp', 0.0)
 
   26         self.
max_amp = rospy.get_param(
'~max_amp', 20.0)
 
   28         max_rate = rospy.get_param(
'~max_rate', -1)
 
   35         self.
fig = plt.figure(figsize=(8, 5))
 
   36         self.
fig.subplots_adjust(left=0.1, right=0.95, top=0.90, bottom=0.1,
 
   37                                  wspace=0.2, hspace=0.6)
 
   38         self.
ax = self.
fig.add_subplot(1, 1, 1)
 
   41         self.
ax.set_title(
'Spectrum plot', fontsize=12)
 
   47         self.
ax.set_xlabel(
'Frequency [Hz]', fontsize=12)
 
   48         self.
ax.set_ylabel(
'Amplitude', fontsize=12)
 
   49         self.line, = self.
ax.plot([0, 0], label=
'Amplitude of Spectrum')
 
   52             '~output/viz', sensor_msgs.msg.Image, queue_size=1)
 
   64             curr_tm = rospy.Time.now().to_sec()
 
   74         self.
amp = np.array(msg.amplitude)
 
   75         self.
freq = np.array(msg.frequency)
 
   76         self.line.set_data(self.
freq, self.
amp)
 
   77         self.
ax.set_xlim((self.
freq.min(), self.
freq.max()))
 
   79         self.
ax.legend(loc=
'upper right')
 
   80         self.
fig.tight_layout()
 
   81         if self.
pub_img.get_num_connections() > 0:
 
   82             bridge = cv_bridge.CvBridge()
 
   84             img_msg = bridge.cv2_to_imgmsg(img, encoding=
'rgb8')
 
   85             img_msg.header = msg.header
 
   89 if __name__ == 
'__main__':
 
   90     rospy.init_node(
'spectrum_plot')