Examples#
This page contains example plots. Click on any image to see the full image and source code.
For longer tutorials, see our tutorials page. You can also find external resources and a FAQ in our user guide.
Lines, bars and markers#
Plotting categorical variables
Plotting the coherence of two signals
Filling the area between lines
Discrete distribution as horizontal bar chart
Customizing dashed line styles
Lines with a ticked patheffect
Plotting masked and NaN values
Mapping marker properties to multivariate data
Scatter plots with custom symbols
Creating a timeline with lines, dates, and text
Cross- and Auto-Correlation Demo
Images, contours and fields#
Interactive Adjustment of Colormap Range
Colormap Normalizations SymLogNorm
Contouring the solution space of optimizations
Blend transparency with color in 2D images
Modifying the coordinate formatter
Contour plot of irregularly spaced data
Advanced quiver and quiverkey functions
Subplots, axes and figures#
Controlling view limits using margins and sticky_edges
Resizing axes with constrained layout
Resizing axes with tight layout
Different scales on the same axes
Figure size in different units
Figure labels: suptitle, supxlabel, supylabel
Combining two subplots using subplots and GridSpec
Using Gridspec to make multi-column/row subplot layouts
Managing multiple figures in pyplot
Creating multiple subplots using plt.subplots
Statistics#
Percentiles as horizontal bar chart
Artist customization in box plots
Box plots with custom fill colors
Box plot vs. violin plot comparison
Plot a confidence ellipse of a two-dimensional dataset
Different ways of specifying error bars
Including upper and lower limits in error bars
Creating boxes from error bars using PatchCollection
Using histograms to plot a cumulative distribution
Some features of the histogram (hist) function
Demo of the histogram function's different histtype settings
The histogram (hist) function with multiple data sets
Producing multiple histograms side by side
Pie and polar charts#
Text, labels and annotations#
Using accented text in Matplotlib
The difference between \dfrac and \frac
Labeling ticks using engineering notation
Annotation arrow style reference
Using a ttf font file in Matplotlib
Fonts demo (object-oriented style)
Fonts demo (keyword arguments)
Legend using pre-defined labels
Rendering math equations using TeX
Controlling style of text and labels using a dictionary
Default text rotation demonstration
Text Rotation Relative To Line
pyplot#
Programmatically controlling subplot adjustment
Color#
For more in-depth information about the colormaps available in matplotlib as well as a description of their properties, see the colormaps tutorial.
Colors in the default property cycle
Creating a colormap from a list of colors
Shapes and collections#
Reference for Matplotlib artists
Line, Poly and RegularPoly Collection with autoscaling
Style sheets#
Bayesian Methods for Hackers style sheet
axes_grid1#
Showing RGB channels using RGBAxes
Adding a colorbar to inset axes
Controlling the position and size of colorbars with Inset Axes
Per-row or per-column colorbars
Axes with a fixed physical size
Setting a fixed aspect on ImageGrid cells
Make room for ylabel using axes_grid
Scatter Histogram (Locatable Axes)
axisartist#
mpl_toolkits.axisartist.floating_axes features
Showcase#
Integral as the area under a curve
Shaded & power normalized rendering
Animation#
Animated image using a precomputed list of images
Pausing and Resuming an Animation
Event handling#
Matplotlib supports event handling with a GUI neutral event model, so you can connect to Matplotlib events without knowledge of what user interface Matplotlib will ultimately be plugged in to. This has two advantages: the code you write will be more portable, and Matplotlib events are aware of things like data coordinate space and which axes the event occurs in so you don't have to mess with low level transformation details to go from canvas space to data space. Object picking examples are also included.
Figure/Axes enter and leave events
Miscellaneous#
Changing colors of lines intersecting a box
Building histograms using Rectangles and PolyCollections
Rasterization for vector graphics
3D plotting#
Create 2D bar graphs in different planes
Demonstrates plotting contour (level) curves in 3D
Demonstrates plotting contour (level) curves in 3D using the extend3d option
Projecting contour profiles onto a graph
Projecting filled contour onto a graph
Custom hillshading in a 3D surface plot
Create 3D histogram of 2D data
Generate polygons to fill under 3D line graph
3D surface with polar coordinates
Triangular 3D filled contour plot
3D voxel plot of the numpy logo
3D voxel / volumetric plot with rgb colors
3D voxel / volumetric plot with cylindrical coordinates
3D wireframe plots in one direction
Scales#
These examples cover how different scales are handled in Matplotlib.
Specialty Plots#
Radar chart (aka spider or star chart)
Long chain of connections using Sankey
SkewT-logP diagram: using transforms and custom projections
Spines#
Ticks#
Automatically setting tick positions
Centering labels between ticks
Formatting date ticks using ConciseDateFormatter
Placing date ticks using recurrence rules
Date tick locators and formatters
Custom tick formatter for time series
Set default y-axis tick labels on the right
Setting tick labels from a list of values
Move x-axis tick labels to the top
Units#
These examples cover the many representations of units in Matplotlib.
Embedding Matplotlib in graphical user interfaces#
You can embed Matplotlib directly into a user interface application by following the embedding_in_SOMEGUI.py examples here. Currently Matplotlib supports PyQt/PySide, PyGObject, Tkinter, and wxPython.
When embedding Matplotlib in a GUI, you must use the Matplotlib API directly rather than the pylab/pyplot procedural interface, so take a look at the examples/api directory for some example code working with the API.
Embedding in GTK3 with a navigation toolbar
Embedding in GTK4 with a navigation toolbar
Embedding in a web application server (Flask)
Userdemo#
Connection styles for annotations
Widgets#
Examples of how to write primitive, but GUI agnostic, widgets in matplotlib
Select indices from a collection using polygon selector
Thresholding an Image with RangeSlider
Rectangle and ellipse selectors
Snapping Sliders to Discrete Values