
- 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 - Filled Plots
A filled plot, also known as a filled area plot or an area chart, is a type of graph used to represent data visually. In a filled plot, the area between the data line and either the x-axis or another reference line is filled with color or pattern.
Imagine you are tracking the daily temperature fluctuations in your city over a month. You can create a filled plot to visualize the range of temperatures each day. On the x-axis, you have the days of the month, and on the y-axis, you have the temperature in degrees Celsius. Each day's temperature range is represented by a filled area, with the area between the highest and lowest temperatures filled with color −

Filled Plots in Matplotlib
A filled plot in Matplotlib is like coloring between the lines on a graph. Instead of just showing points or lines, it fills in the area between those points or lines with color. This can help you see the shape of the data more clearly.
We can use the fill_between() function from the 'pyplot' module to create filled plots in Matplotlib. This function accepts the X and Y coordinates as arrays and fills a specific color in the area enclosed by the curves in a 2D space.
Lets start by drawing a basic filled plot.
Basic Filled Plot
A basic filled plot in Matplotlib is a visualization where the area under a line connecting data points is filled with color. This type of plot helps to visually interpret data and identify patterns or trends more easily.
Example
In the following example, we are creating a filled line plot. We generate the x-axis values ranging from 0 to 10 and then calculate the corresponding y-axis values by taking the sine of each x-axis value. Next, we fill the area under the line and above the x-axis with color, resulting in a filled line plot −
import matplotlib.pyplot as plt import numpy as np # Creating sample data x = np.linspace(0, 10, 100) y = np.sin(x) # Creating a filled line plot plt.fill_between(x, y, color='skyblue', alpha=0.4, label='Filled Line') # Adding labels and title plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Basic Filled Plot') # Displaying the plot plt.show()
Output
Following is the output of the above code −

Filled Plot between Two Lines
A filled plot between two lines in Matplotlib refers to coloring the area between two lines on a graph. The two lines traverse the XY plane, and wherever they form an enclosed region, it is filled with color.
Example
In here, we are creating a filled plot between two lines in the XY plane. The two lines 'Y1' and 'Y2' are calculated by taking the sine and cosine values of the x-axis values, respectively. We then fill the area enclosed by the two lines to create the resultant filled plot between two lines −
import matplotlib.pyplot as plt import numpy as np # Creating sample data x = np.linspace(0, 10, 100) y1 = np.sin(x) y2 = np.cos(x) # Creating a filled plot between two lines plt.fill_between(x, y1, y2, color='lightgreen', alpha=0.4, label='Filled Between Lines') # Adding labels and title plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Filled Plot between Two Lines') # Displaying the plot plt.show()
Output
Output of the above code is as follows −

Example
In here, we are creating a filled plot between two vertical lines. We use the axvspan() function to add vertical span(rectangle) across the axes. This rectangle spans from xmin to xmax horizontally, and, by default, the whole Y-axis vertically −
import matplotlib.pyplot as plt fig, ax = plt.subplots() line1 = 3 # vertical x = 3 line2 = 5 # vertical x = 5 ax.axvspan(line1, line2, alpha=.5, color='green') plt.show()
Output
We get the output as shown below −

Filled Polar Area Plot
In Matplotlib, a filled polar area plot represents a visualization where the area enclosed by a curve is filled with color. The curve is created in the polar coordinate system, meaning that the position of the data points is determined by the radius and angle instead of X and Y coordinates.
Example
The following example generates a filled polar area plot. The coordinates of the data points are defined by the angle (theta), ranging from 0 to 2, and the radius (r) of curve, which varies with the cosine of the angle. The area under the curve is filled with color. In the resultant plot, the polar area under the curve is filled −
import matplotlib.pyplot as plt import numpy as np # Creating sample data for a polar plot theta = np.linspace(0, 2 * np.pi, 100) r = 3 + 2 * np.cos(6 * theta) # Creating a filled polar area plot plt.fill_between(theta, r, color='purple', alpha=0.5, label='Filled Polar Area Plot') # Adding title plt.title('Filled Polar Area Plot') # Displaying the plot plt.show()
Output
After executing the above code, we get the following output −

Filled Plot from Irregular Data
In Matplotlib, a filled plot from irregular data is a way to represent a colored region on a graph, where the data points are irregularly spaced. The area enclosed by these points and the x-axis is filled with color.
Example
Now, we are filling the plot under a curve created using irregularly spaced data points on a graph. We define the data points using arrays for the x-axis and the y-axis. The region enclosed by these points is filled with color −
import matplotlib.pyplot as plt import numpy as np # Creating irregular data points x = np.array([1, 2, 3, 4, 5, 4, 3, 2, 1]) y = np.array([0, 1, 0, 1, 0, -1, 0, -1, 0]) # Plotting the irregular data points plt.plot(x, y, color='blue', label='Irregular Data Points', marker='o') # Creating a polygon to fill between the curve and the x-axis plt.fill_between(x, y, color='lightgreen', alpha=0.5, label='Filled Plot from Irregular Data') # Adding labels and title plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.title('Filled Plot from Irregular Data') # Displaying the plot plt.show()
Output
The output obtained is as shown below −
