
- 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 - Step Plots
A step plot is a type of graph that shows how values change abruptly at specific points, rather than changing continuously. It looks like a series of horizontal and vertical lines connecting the data points. Each horizontal line represents a period where the value remains constant, and each vertical line indicates when the value changes to a new level.
Imagine you are monitoring the temperature of a room throughout the day. You take measurements every hour, and instead of recording every slight change, you note the temperature only when it significantly shifts, like when the air conditioning turns on or off. A step plot of this data would show a horizontal line for each period when the temperature remains constant, connected by vertical lines where the temperature changes abruptly −

Step Plots in Matplotlib
In Matplotlib, a step plot is a type of graph that connects data points using horizontal and vertical lines in the XY plane, forming a series of steps. We can use the step() function from the 'pyplot' module to create a step plot. This function accepts the X and Y coordinates as arrays. It connects the X coordinates horizontally until it reaches an X coordinate where the value of Y coordinate changes vertically to a new constant.
Lets start by drawing a basic step plot.
Basic Step Plot
A basic step plot in Matplotlib visually represents a plot where the steps are present at the midpoint of each interval. This means that the change in the y-axis value occurs at the midpoint between two x-axis values. For example, if the x-axis has values 1 and 2, then the step will be present at the value 1.5.
Example
In the following example, we are creating a basic step plot. The data points consists of two arrays, 'x' and 'y,' which represent the values along the x-axis and y-axis, respectively. We are then joining the data points at the center of the interval −
import matplotlib.pyplot as plt import numpy as np # Generating data x = np.array([1, 2, 3, 4, 5]) y = np.array([2, 4, 1, 3, 5]) # Creating a basic step plot plt.step(x, y, where='mid', color='blue', label='Step Plot') # Adding labels and title plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Basic Step Plot') # Displaying the plot plt.show()
Output
Following is the output of the above code −

Post Step Plot
A post step plot in Matplotlib represents a plot where the steps are positioned at the end of each interval. This means that the change in the y-axis value occurs at the endpoint of the x-axis values.
We can create a post step plot in Matplotlib by specifying the value 'post' to the 'where' parameter. This type of plot creates a staircase-like pattern. For example, if the x-axis has values 1 and 2, then the step will be present at the value 2.
Example
In here, we are generating a post step plot. The data points are represented by two arrays, 'x' and 'y', for the x-axis and the y-axis values, respectively. We then join the data points at the end of each interval by setting the 'where' parameter to 'post' −
import matplotlib.pyplot as plt import numpy as np # Generating data x = np.array([1, 2, 3, 4, 5]) y = np.array([2, 4, 1, 3, 5]) # Creating a step plot with 'post' where parameter plt.step(x, y, where='post', color='green', label='Step Plot with "post"') # Adding labels and title plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Post Step Plot') # Displaying the plot plt.show()
Output
Output of the above code is as follows −

Pre Step Plot
In Matplotlib, a pre step plot refers to creating a plot where the steps are positioned at the start of each interval. This means that the change in the y-axis value occurs at the starting point of the x-axis values.
We can create a pre step plot in Matplotlib by specifying the value 'pre' to the 'where' parameter. For example, if the x-axis has values 1 and 2, then the step will be present at the value 1.
Example
The following example creates a pre step plot. The data points are represented by two arrays, 'x' and 'y', which define the values for the x-axis and the y-axis, respectively. We then join the data points at the start of each interval by setting the 'where' parameter to 'pre' −
import matplotlib.pyplot as plt import numpy as np # Generating data x = np.array([1, 2, 3, 4, 5]) y = np.array([2, 4, 1, 3, 5]) # Creating a step plot with 'pre' where parameter plt.step(x, y, where='pre', color='red', label='Step Plot with "pre"') # Adding labels and title plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Pre Step Plot') # Displaying the plot plt.show()
Output
After executing the above code, we get the following output −

Sinusoidal Step Plot
A sinusoidal step plot in Matplotlib is a visualization of a plot where the steps form a sinusoidal wave in the XY plane. This means that the steps are continuously present throughout the graph instead of being located at specific locations.
Example
Now, we are generating a sinusoidal step plot in Matplotlib. Here, we first create the x-axis values from 0 to 10 and then calculate the y-axis values by taking the sine value of each x-axis value. We then combine the data points to produce a continuous step plot −
import matplotlib.pyplot as plt import numpy as np # Generating data x = np.linspace(0, 10, 100) y = np.sin(x) # Creating a basic step plot plt.step(x, y, where='mid', color='blue', label='Step Plot') # Adding labels and title plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Sinusoidal Step Plot') # Displaying the plot plt.show()
Output
The output obtained is as shown below −
