
- Matplotlib - Home
- Matplotlib - Introduction
- Matplotlib - Vs Seaborn
- Matplotlib - Environment Setup
- Matplotlib - Anaconda distribution
- Matplotlib - Jupyter Notebook
- Matplotlib - Pyplot API
- Matplotlib - Simple Plot
- Matplotlib - Saving Figures
- Matplotlib - Markers
- Matplotlib - Figures
- Matplotlib - Styles
- Matplotlib - Legends
- Matplotlib - Colors
- Matplotlib - Colormaps
- Matplotlib - Colormap Normalization
- Matplotlib - Choosing Colormaps
- Matplotlib - Colorbars
- Matplotlib - Working With Text
- Matplotlib - Text properties
- Matplotlib - Subplot Titles
- Matplotlib - Images
- Matplotlib - Image Masking
- Matplotlib - Annotations
- Matplotlib - Arrows
- Matplotlib - Fonts
- Matplotlib - Font Indexing
- Matplotlib - Font Properties
- Matplotlib - Scales
- Matplotlib - LaTeX
- Matplotlib - LaTeX Text Formatting in Annotations
- Matplotlib - PostScript
- Matplotlib - Mathematical Expressions
- Matplotlib - Animations
- Matplotlib - Celluloid Library
- Matplotlib - Blitting
- Matplotlib - Toolkits
- Matplotlib - Artists
- Matplotlib - Styling with Cycler
- Matplotlib - Paths
- Matplotlib - Path Effects
- Matplotlib - Transforms
- Matplotlib - Ticks and Tick Labels
- Matplotlib - Radian Ticks
- Matplotlib - Dateticks
- Matplotlib - Tick Formatters
- Matplotlib - Tick Locators
- Matplotlib - Basic Units
- Matplotlib - Autoscaling
- Matplotlib - Reverse Axes
- Matplotlib - Logarithmic Axes
- Matplotlib - Symlog
- Matplotlib - Unit Handling
- Matplotlib - Ellipse with Units
- Matplotlib - Spines
- Matplotlib - Axis Ranges
- Matplotlib - Axis Scales
- Matplotlib - Axis Ticks
- Matplotlib - Formatting Axes
- Matplotlib - Axes Class
- Matplotlib - Twin Axes
- Matplotlib - Figure Class
- Matplotlib - Multiplots
- Matplotlib - Grids
- Matplotlib - Object-oriented Interface
- Matplotlib - PyLab module
- Matplotlib - Subplots() Function
- Matplotlib - Subplot2grid() Function
- Matplotlib - Anchored Artists
- Matplotlib - Manual Contour
- Matplotlib - Coords Report
- Matplotlib - AGG filter
- Matplotlib - Ribbon Box
- Matplotlib - Fill Spiral
- Matplotlib - Findobj Demo
- Matplotlib - Hyperlinks
- Matplotlib - Image Thumbnail
- Matplotlib - Plotting with Keywords
- Matplotlib - Create Logo
- Matplotlib - Multipage PDF
- Matplotlib - Multiprocessing
- Matplotlib - Print Stdout
- Matplotlib - Compound Path
- Matplotlib - Sankey Class
- Matplotlib - MRI with EEG
- Matplotlib - Stylesheets
- Matplotlib - Background Colors
- Matplotlib - Basemap
- Matplotlib - Event Handling
- Matplotlib - Close Event
- Matplotlib - Mouse Move
- Matplotlib - Click Events
- Matplotlib - Scroll Event
- Matplotlib - Keypress Event
- Matplotlib - Pick Event
- Matplotlib - Looking Glass
- Matplotlib - Path Editor
- Matplotlib - Poly Editor
- Matplotlib - Timers
- Matplotlib - Viewlims
- Matplotlib - Zoom Window
- Matplotlib Widgets
- Matplotlib - Cursor Widget
- Matplotlib - Annotated Cursor
- Matplotlib - Buttons Widget
- Matplotlib - Check Buttons
- Matplotlib - Lasso Selector
- Matplotlib - Menu Widget
- Matplotlib - Mouse Cursor
- Matplotlib - Multicursor
- Matplotlib - Polygon Selector
- Matplotlib - Radio Buttons
- Matplotlib - RangeSlider
- Matplotlib - Rectangle Selector
- Matplotlib - Ellipse Selector
- Matplotlib - Slider Widget
- Matplotlib - Span Selector
- Matplotlib - Textbox
- Matplotlib Plotting
- Matplotlib - Line Plots
- Matplotlib - Area Plots
- Matplotlib - Bar Graphs
- Matplotlib - Histogram
- Matplotlib - Pie Chart
- Matplotlib - Scatter Plot
- Matplotlib - Box Plot
- Matplotlib - Arrow Demo
- Matplotlib - Fancy Boxes
- Matplotlib - Zorder Demo
- Matplotlib - Hatch Demo
- Matplotlib - Mmh Donuts
- Matplotlib - Ellipse Demo
- Matplotlib - Bezier Curve
- Matplotlib - Bubble Plots
- Matplotlib - Stacked Plots
- Matplotlib - Table Charts
- Matplotlib - Polar Charts
- Matplotlib - Hexagonal bin Plots
- Matplotlib - Violin Plot
- Matplotlib - Event Plot
- Matplotlib - Heatmap
- Matplotlib - Stairs Plots
- Matplotlib - Errorbar
- Matplotlib - Hinton Diagram
- Matplotlib - Contour Plot
- Matplotlib - Wireframe Plots
- Matplotlib - Surface Plots
- Matplotlib - Triangulations
- Matplotlib - Stream plot
- Matplotlib - Ishikawa Diagram
- Matplotlib - 3D Plotting
- Matplotlib - 3D Lines
- Matplotlib - 3D Scatter Plots
- Matplotlib - 3D Contour Plot
- Matplotlib - 3D Bar Plots
- Matplotlib - 3D Wireframe Plot
- Matplotlib - 3D Surface Plot
- Matplotlib - 3D Vignettes
- Matplotlib - 3D Volumes
- Matplotlib - 3D Voxels
- Matplotlib - Time Plots and Signals
- Matplotlib - Filled Plots
- Matplotlib - Step Plots
- Matplotlib - XKCD Style
- Matplotlib - Quiver Plot
- Matplotlib - Stem Plots
- Matplotlib - Visualizing Vectors
- Matplotlib - Audio Visualization
- Matplotlib - Audio Processing
- Matplotlib Useful Resources
- Matplotlib - Quick Guide
- Matplotlib - Cheatsheet
- Matplotlib - Useful Resources
- Matplotlib - Discussion
Matplotlib - Time Plots and Signals
A time plot is a graph that represents the change of a variable over a certain time period. Similarly, signals represent the change in the amplitude of a wave over a time period. In a two-dimensional space, time is plotted on the horizontal axis, while the value is plotted on the vertical axis.
Imagine we are measuring the temperature every hour for a day. We plot the time on x-axis and the temperature on y-axis. Connecting the y-axis values through a line represents the time plot −

Time Plots and Signals in Matplotlib
Time plots and signals in Matplotlib refer to visual representations of changes in data values over a time period. They display how data points vary with respect to time.
Matplotlib does not have a separate function specifically for creating time plots or signals. Instead, we use the plot() function to generate these plots. This function accepts the X and Y coordinates as arrays and connects them using lines to create a time plot or signal
Lets start by drawing a basic time plot.
Basic Time Plot
A basic time plot in Matplotlib is a way to visualize changes in data over time. It involves plotting points on a graph where the x-axis represents time and the y-axis represents the values of the data. The plot is formed is formed by connecting the y-axis values as we progress along the x-axis.
Example
The following example creates a basic time plot in Matplotlib. We create two arrays: 'time' represents the time period, and 'values' represents the corresponding values collected at each time period.
Then, we use the plot() function to connect the different values on y-axis. This results in a plot that shows changes in values over time −
import matplotlib.pyplot as plt # Sample time-series data time = [0, 1, 2, 3, 4, 5] values = [10, 15, 20, 18, 25, 30] # Creating a time plot plt.plot(time, values, marker='o') # Adding labels and title plt.xlabel('Time') plt.ylabel('Value') plt.title('Basic Time Plot') # Displaying the plot plt.show()
Output
Following is the output of the above code −

Sine Wave Signal
A sine wave signal in Matplotlib represents a wave that varies sinusoidally over time. Time is plotted on the x-axis, while the amplitude of the wave is plotted on the y-axis. A sine wave signal looks like a smooth, wavy line when plotted on a graph, with peaks and troughs repeating at regular time intervals.
Example
In here, we are generating a sine wave signal to display the amplitude of a wave over a time period. First, we create an array of evenly spaced time intervals 't' ranging from the 0 to 10.
Then, we define the amplitude (height of the wave) and frequency (number of cycles made in a given time interval) of the wave. Using time, frequency and amplitude, we create a sine wave signal. The resultant plot displays a sine signal that repeats at regular intervals −
import matplotlib.pyplot as plt import numpy as np # Generating time values t = np.linspace(0, 10, 100) # Generating sine wave signal frequency = 0.5 amplitude = 5 signal = amplitude * np.sin(2 * np.pi * frequency * t) # Plotting the sine wave signal plt.plot(t, signal) # Adding labels and title plt.xlabel('Time') plt.ylabel('Amplitude') plt.title('Sine Wave Signal') # Displaying the plot plt.show()
Output
Output of the above code is as follows −

Random Time Plot
In Matplotlib, a random time plot is a visualization of a sequence of data points that change randomly over a time period. This is achieved by adding a random value to the previous data point, resulting in an irregular time plot.
Example
The following example creates a random time plot to display the random change in values over a time period. We start by creating a time interval ranging from 0 to 99.
Next, we generate random values for the y-axis by using the np.random.randn() function and calculate the cumulative sum at each time period using the np.cumsum() function. Then, we use the plot() function to generate the resultant plot where the data values are randomly plotted −
import matplotlib.pyplot as plt import numpy as np # Generating time values t = np.arange(0, 100) # Generating random walk time series np.random.seed(5) signal = np.cumsum(np.random.randn(100)) # Plotting the random walk time series plt.plot(t, signal) # Adding labels and title plt.xlabel('Time') plt.ylabel('Value') plt.title('Random Time Plot') # Displaying the plot plt.show()
Output
After executing the above code, we get the following output −

Step Function Signal
A step function signal in Matplotlib defines a signal whose values change significantly at specific points in time. In a step function signal, horizontal lines are connected by vertical lines that indicate the moments when the value changes. Step function signals represent events that occur instantaneously.
Example
Now, we are creating a step function signal in Matplotlib to display sudden changes in values at a given time period. We start by defining a time interval ranging from 0 to 10. Then, we use the np.piecewise() function to create the condition for when the values on y-axis should change.
The condition we use is as follows: "The amplitude remains 0 until t reaches 4 seconds. Then, at t=4 seconds, the amplitude changes to 1 and remains 1 until time reaches 6 seconds. Finally, at t=6 seconds, the amplitude returns to 0" −
import matplotlib.pyplot as plt import numpy as np # Generating time values t = np.linspace(0, 10, 100) # Generating step function signal signal = np.piecewise(t, [t < 4, (t >= 4) & (t < 6), t >= 6], [0, 1, 0]) # Plotting the step function signal plt.plot(t, signal) # Adding labels and title plt.xlabel('Time') plt.ylabel('Amplitude') plt.title('Step Function Signal') # Displaying the plot plt.show()
Output
The output obtained is as shown below −
