title: smoothing out data so plotting using matplotlib and FFT data looks nicer ( frequency spectrum )
body: <p>basically i have the fundamentals of a music visualiser however i would like to improve it,at the moment im getting lots of data and plotting the absolute value of my fft calculations, however this looks very messy and i would like it to be smoothed out somewhat, i will post a gif of what its like below. i would the data to be smoothed out so there is less spikes in noise, and to remove the odd values being plotted at 0 on the x axis and really high up on the y axis as it happens whenever theres noise at all, it also goes off the graph which i dont like.</p>
  
  <p>gif of example : <a href="https://i.imgur.com/eOGzPFd.gifv" rel="nofollow noreferrer">https://i.imgur.com/eOGzPFd.gifv</a></p>
  
  <p>video of smoothed visualiser: <a href="https://www.youtube.com/watch?v=C2TV2DaCVk0" rel="nofollow noreferrer">https://www.youtube.com/watch?v=C2TV2DaCVk0</a></p>
  
  <p>is it smoothed just because its seperated and plotted as bars? because that is my eventual goal, is to seperate the data into bars and plot it like that. i also prefer being able to see more of a variation in the graph when music is going up in low frequencies, however testing a range of low frequencies on my graph, it doesnt seem to show the difference.</p>
  
  <p>i appreciate all the help anyone has given me previously and anyone who continues to help me!!! &lt;3</p>
  
  <pre><code>import pyaudio
  import numpy as np
  import time
  import matplotlib.animation as animation
  import matplotlib.pyplot as plt
  from matplotlib import style
  
  pa = pyaudio.PyAudio()
  audio_data = 0
  callback_output = []
  
  def callback(in_data, frame_count, time_info, flag):
      global audio_data
      audio_data = np.fromstring(in_data, dtype=np.float32)
      callback_output.append(audio_data)
      return None,pyaudio.paContinue
  
  
  stream = pa.open(format=pyaudio.paFloat32,
                   channels=1,
                   rate=44100,
                   output=False,
                   input=True,
                   stream_callback=callback)
  
  stream.start_stream()
  
  plt.ion() # Stop matplotlib windows from blocking
  
  # Setup figure, axis and initiate plot
  fig, ax = plt.subplots()
  ln, = ax.plot([], [], 'b,:')
  
  x = 0
  
  while stream.is_active():
  
      fft_data = np.fft.fft(audio_data)
      fft_freq = np.fft.fftfreq(len(fft_data),d=1/44100)
  
      ln.set_xdata(np.abs(fft_freq))
      ln.set_ydata(np.abs((fft_data)))
  
  
      fig.canvas.draw()
      fig.canvas.flush_events()
  
      if x == 0:
          ax.relim()
          ax.autoscale_view()
          ax.set_xlim([-500,15000])
          ax.set_ylim([0,5])
          x=1
  
  stream.close()
  pa.terminate()
  </code></pre>