Plotting Various Sounds on Graphs using Python and Matplotlib Last Updated : 15 Jul, 2025 Comments Improve Suggest changes 4 Likes Like Report See More In this article, we will explore the way of visualizing sounds waves using Python and Matplotlib. Modules Needed 1. Matplotlib: Install Matplotlib using the below command: pip install matplotlib 2. Numpy: Numpy gets installed automatically installed with Matplotlib. Although, if you face any import error, use the below command to install Numpy pip install numpy Note: If you are on Linux like me, then you might need to use pip3 instead of pip or you might create a virtual environment and run the above command. ApproachImport matplotlib, Numpy, wave, and sys module.Open the audio file using the wave.open() method.Read all frames of the opened sound wave using readframes() function.Store the frame rate in a variable using the getframrate() function.Finally, plot the x-axis in seconds using frame rate.Use the matplotlib.figure() function to plot the derived graphUse labels as per the requirement. Below is the implementation. Python3 # imports import matplotlib.pyplot as plt import numpy as np import wave, sys # shows the sound waves def visualize(path: str): # reading the audio file raw = wave.open(path) # reads all the frames # -1 indicates all or max frames signal = raw.readframes(-1) signal = np.frombuffer(signal, dtype ="int16") # gets the frame rate f_rate = raw.getframerate() # to Plot the x-axis in seconds # you need get the frame rate # and divide by size of your signal # to create a Time Vector # spaced linearly with the size # of the audio file time = np.linspace( 0, # start len(signal) / f_rate, num = len(signal) ) # using matplotlib to plot # creates a new figure plt.figure(1) # title of the plot plt.title("Sound Wave") # label of x-axis plt.xlabel("Time") # actual plotting plt.plot(time, signal) # shows the plot # in new window plt.show() # you can also save # the plot using # plt.savefig('filename') if __name__ == "__main__": # gets the command line Value path = sys.argv[1] visualize(path) Output: So, we are done with coding, now it's the moment of truth. Let's check if it actually works or not. You can try out any audio file but make sure that it has to be a wav file. If you have some other file type then you can use ffmpeg to convert it to wav file. If you want then feel free to download the audio file we will be using. You can download it using the link https://file-examples.com/wp-content/uploads/2017/11/file_example_WAV_1MG.wav", but do try out other files too.To run the code, you need to pass the path of the audio file in the command line. To do that type the following in your terminal: python soundwave.py sample_audio.wav It is important to note that name of the Python file is soundwave.py and the name of the audio file is sample_audio.wav. You need to change these according to your system. Now, a new window should have popped up and should be seeing a sound wave plot. If you have used my audio, then your plot should look something like this. Create Quiz Comment D debdutgoswami Follow 4 Improve D debdutgoswami Follow 4 Improve Article Tags : Python Python-matplotlib Data Visualization Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like